Skip to content

Commit 0951942

Browse files
committed
jit: Fix type used for Datum values in LLVM IR.
Commit 2a600a9 made Datum 8 bytes wide everywhere. It was no longer appropriate to use TypeSizeT on 32 bit systems, and JIT compilation would fail with various type check errors. Introduce a separate LLVMTypeRef with the name TypeDatum. TypeSizeT is still used in some places for actual size_t values. Reported-by: Dmitry Mityugov <d.mityugov@postgrespro.ru> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Tested-by: Dmitry Mityugov <d.mityugov@postgrespro.ru> Discussion: https://postgr.es/m/0a9f0be59171c2e8f1b3bc10f4fcf267%40postgrespro.ru
1 parent 39f67d9 commit 0951942

File tree

6 files changed

+94
-81
lines changed

6 files changed

+94
-81
lines changed

src/backend/jit/llvm/llvmjit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct LLVMJitHandle
5454

5555
/* types & functions commonly needed for JITing */
5656
LLVMTypeRef TypeSizeT;
57+
LLVMTypeRef TypeDatum;
5758
LLVMTypeRef TypeParamBool;
5859
LLVMTypeRef TypeStorageBool;
5960
LLVMTypeRef TypePGFunction;
@@ -1011,6 +1012,7 @@ llvm_create_types(void)
10111012
LLVMDisposeMemoryBuffer(buf);
10121013

10131014
TypeSizeT = llvm_pg_var_type("TypeSizeT");
1015+
TypeDatum = llvm_pg_var_type("TypeDatum");
10141016
TypeParamBool = load_return_type(llvm_types_module, "FunctionReturningBool");
10151017
TypeStorageBool = llvm_pg_var_type("TypeStorageBool");
10161018
TypePGFunction = llvm_pg_var_type("TypePGFunction");

src/backend/jit/llvm/llvmjit_deform.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
479479
l_gep(b, LLVMInt8TypeInContext(lc), v_tts_nulls, &l_attno, 1, ""));
480480
/* store zero datum */
481481
LLVMBuildStore(b,
482-
l_sizet_const(0),
483-
l_gep(b, TypeSizeT, v_tts_values, &l_attno, 1, ""));
482+
l_datum_const(0),
483+
l_gep(b, TypeDatum, v_tts_values, &l_attno, 1, ""));
484484

485485
LLVMBuildBr(b, b_next);
486486
attguaranteedalign = false;
@@ -644,7 +644,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
644644
}
645645

646646
/* compute address to store value at */
647-
v_resultp = l_gep(b, TypeSizeT, v_tts_values, &l_attno, 1, "");
647+
v_resultp = l_gep(b, TypeDatum, v_tts_values, &l_attno, 1, "");
648648

649649
/* store null-byte (false) */
650650
LLVMBuildStore(b, l_int8_const(lc, 0),
@@ -663,7 +663,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
663663
v_tmp_loaddata =
664664
LLVMBuildPointerCast(b, v_attdatap, vartypep, "");
665665
v_tmp_loaddata = l_load(b, vartype, v_tmp_loaddata, "attr_byval");
666-
v_tmp_loaddata = LLVMBuildZExt(b, v_tmp_loaddata, TypeSizeT, "");
666+
v_tmp_loaddata = LLVMBuildZExt(b, v_tmp_loaddata, TypeDatum, "");
667667

668668
LLVMBuildStore(b, v_tmp_loaddata, v_resultp);
669669
}
@@ -675,7 +675,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
675675
v_tmp_loaddata =
676676
LLVMBuildPtrToInt(b,
677677
v_attdatap,
678-
TypeSizeT,
678+
TypeDatum,
679679
"attr_ptr");
680680
LLVMBuildStore(b, v_tmp_loaddata, v_resultp);
681681
}

0 commit comments

Comments
 (0)