From f46f9a2edd6ed36938fae53071144a67d7ae5a5b Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Mon, 26 Oct 2026 10:56:44 +0900 Subject: [PATCH v4 3/4] Make the LLVM JIT work on an AddressSanitizer build After the previous commit, a JIT-compiled query on a build with -fsanitize=address fails with "variable TypeSizeT in llvmjit_types.c is not of its declared type". AddressSanitizer gives each variable in llvmjit_types.c the type { T, [N x i8] }: the object of the declared type T at offset zero, followed by a redzone. Those variables only carry types to the JIT; their addresses and contents are never used. So have llvm_pg_var_type() take T from such a type. JIT-compiled queries then run normally on an AddressSanitizer build, and the jit regression test passes there. --- src/backend/jit/llvm/llvmjit.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index aea7d9b9989..83c67bb9154 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -432,6 +432,24 @@ llvm_pg_var_type(const char *varname) typ = LLVMGlobalGetValueType(v_srcvar); + /* + * When llvmjit_types.c is compiled with -fsanitize=address, + * AddressSanitizer gives each variable the type { T, [N x i8] }: the + * object of the declared type T at offset zero, followed by a redzone. + * Take T from it. + */ + if (LLVMGetTypeKind(typ) == LLVMStructTypeKind && + LLVMIsLiteralStruct(typ) && + LLVMCountStructElementTypes(typ) == 2) + { + LLVMTypeRef redzone = LLVMStructGetTypeAtIndex(typ, 1); + + if (LLVMGetTypeKind(redzone) == LLVMArrayTypeKind && + LLVMGetTypeKind(LLVMGetElementType(redzone)) == LLVMIntegerTypeKind && + LLVMGetIntTypeWidth(LLVMGetElementType(redzone)) == 8) + typ = LLVMStructGetTypeAtIndex(typ, 0); + } + /* * The variables in llvmjit_types.c are of scalar or named struct types, * so a variable of an unnamed struct type is not of its declared type. -- 2.54.0 (Apple Git-157)