aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2024-04-10 10:46:15 +1200
committerThomas Munro <tmunro@postgresql.org>2024-04-10 12:14:04 +1200
commit74992929a79e2606fbc4d579c3fad04a890eda04 (patch)
tree243707105c39f74ca2631774c1a8b10fca2e2da8
parent6304ee667759852083197c425668ae381ba82c22 (diff)
downloadpostgresql-74992929a79e2606fbc4d579c3fad04a890eda04.tar.gz
postgresql-74992929a79e2606fbc4d579c3fad04a890eda04.zip
Fix illegal attribute propagation in LLVM JIT.
Commit 72559438 started copying more attributes from AttributeTemplate to the functions we generate on the fly. In the case of deform functions, which return void, this meant that "noundef", from AttributeTemplate's return value (a Datum) was copied to a void type. Older LLVM releases were OK with that, but LLVM 18 crashes. Update our llvm_copy_attributes() function to skip copying the attribute for the return value, if the target function returns void. Thanks to Dmitry Dolgov for help chasing this down. Back-patch to all supported releases, like 72559438. Reported-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Dmitry Dolgov <9erthalion6@gmail.com> Discussion: https://postgr.es/m/CAFj8pRACpVFr7LMdVYENUkScG5FCYMZDDdSGNU-tch%2Bw98OxYg%40mail.gmail.com
-rw-r--r--src/backend/jit/llvm/llvmjit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index a4b9ede1f65..8b00d981121 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -565,8 +565,11 @@ llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
/* copy function attributes */
llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeFunctionIndex);
- /* and the return value attributes */
- llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeReturnIndex);
+ if (LLVMGetTypeKind(LLVMGetFunctionReturnType(v_to)) != LLVMVoidTypeKind)
+ {
+ /* and the return value attributes */
+ llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeReturnIndex);
+ }
/* and each function parameter's attribute */
param_count = LLVMCountParams(v_from);