jit: Correct parameter type for generated expression evaluation functions.
authorAndres Freund
Tue, 8 Dec 2020 02:21:06 +0000 (18:21 -0800)
committerAndres Freund
Tue, 8 Dec 2020 02:39:32 +0000 (18:39 -0800)
clang only uses the 'i1' type for scalar booleans, not for pointers to
booleans (as the pointer might be pointing into a larger memory
allocation). Therefore a pointer-to-bool needs to the "storage" boolean.

There's no known case of wrong code generation due to this, but it seems quite
possible that it could cause problems (see e.g. 72559438f92).

Author: Andres Freund
Discussion: https://postgr.es/m/20201207212142[email protected]
Backpatch: 11-, where jit support was added

src/backend/jit/llvm/llvmjit_expr.c

index 30133634c70b246b29d9156ef64c44ad3a98edd2..6ed02639bb9952659889c4b16c51aebc43d02afe 100644 (file)
@@ -151,7 +151,7 @@ llvm_compile_expr(ExprState *state)
 
        param_types[0] = l_ptr(StructExprState);    /* state */
        param_types[1] = l_ptr(StructExprContext);  /* econtext */
-       param_types[2] = l_ptr(TypeParamBool);  /* isnull */
+       param_types[2] = l_ptr(TypeStorageBool);    /* isnull */
 
        eval_sig = LLVMFunctionType(TypeSizeT,
                                    param_types, lengthof(param_types),
@@ -258,8 +258,6 @@ llvm_compile_expr(ExprState *state)
 
                    v_tmpvalue = LLVMBuildLoad(b, v_tmpvaluep, "");
                    v_tmpisnull = LLVMBuildLoad(b, v_tmpisnullp, "");
-                   v_tmpisnull =
-                       LLVMBuildTrunc(b, v_tmpisnull, TypeParamBool, "");
 
                    LLVMBuildStore(b, v_tmpisnull, v_isnullp);