Fix illegal attribute propagation in LLVM JIT.
authorThomas Munro <[email protected]>
Tue, 9 Apr 2024 22:46:15 +0000 (10:46 +1200)
committerThomas Munro <[email protected]>
Wed, 10 Apr 2024 00:15:59 +0000 (12:15 +1200)
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 <[email protected]>
Reviewed-by: Dmitry Dolgov <[email protected]>
Discussion: https://postgr.es/m/CAFj8pRACpVFr7LMdVYENUkScG5FCYMZDDdSGNU-tch%2Bw98OxYg%40mail.gmail.com

src/backend/jit/llvm/llvmjit.c

index 07a720d3e42df1178be40a6af0f6e044e557af32..8e717875c3a655d6ab8d78e747f7fb039715322d 100644 (file)
@@ -570,8 +570,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);