From 0951942bba25f85ad29a4f096ed51a356652b5a2 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Wed, 17 Sep 2025 12:00:16 +1200 Subject: jit: Fix type used for Datum values in LLVM IR. Commit 2a600a93 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 Reviewed-by: Tom Lane Tested-by: Dmitry Mityugov Discussion: https://postgr.es/m/0a9f0be59171c2e8f1b3bc10f4fcf267%40postgrespro.ru --- src/include/jit/llvmjit.h | 1 + src/include/jit/llvmjit_emit.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/include/jit') diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h index 5038cf33e3f..b3c75022f55 100644 --- a/src/include/jit/llvmjit.h +++ b/src/include/jit/llvmjit.h @@ -74,6 +74,7 @@ typedef struct LLVMJitContext extern PGDLLIMPORT LLVMTypeRef TypeParamBool; extern PGDLLIMPORT LLVMTypeRef TypePGFunction; extern PGDLLIMPORT LLVMTypeRef TypeSizeT; +extern PGDLLIMPORT LLVMTypeRef TypeDatum; extern PGDLLIMPORT LLVMTypeRef TypeStorageBool; extern PGDLLIMPORT LLVMTypeRef StructNullableDatum; diff --git a/src/include/jit/llvmjit_emit.h b/src/include/jit/llvmjit_emit.h index df5a9fc8500..0e57a332b6e 100644 --- a/src/include/jit/llvmjit_emit.h +++ b/src/include/jit/llvmjit_emit.h @@ -86,6 +86,15 @@ l_sizet_const(size_t i) return LLVMConstInt(TypeSizeT, i, false); } +/* + * Emit constant integer. + */ +static inline LLVMValueRef +l_datum_const(Datum i) +{ + return LLVMConstInt(TypeDatum, i, false); +} + /* * Emit constant boolean, as used for storage (e.g. global vars, structs). */ @@ -313,7 +322,7 @@ l_funcnull(LLVMBuilderRef b, LLVMValueRef v_fcinfo, size_t argno) static inline LLVMValueRef l_funcvalue(LLVMBuilderRef b, LLVMValueRef v_fcinfo, size_t argno) { - return l_load(b, TypeSizeT, l_funcvaluep(b, v_fcinfo, argno), ""); + return l_load(b, TypeDatum, l_funcvaluep(b, v_fcinfo, argno), ""); } #endif /* USE_LLVM */ -- cgit v1.2.3