From c6ad690dc5c5cd50f0123085640772f8240ed84a Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Mon, 26 Oct 2026 10:56:44 +0900 Subject: [PATCH v4 2/4] Raise an error for a JIT type variable of an unexpected form The JIT takes the LLVM types of PostgreSQL's structs and scalars from the global variables in llvmjit_types.c, all of which are of scalar or named struct types. Make llvm_pg_var_type() raise an error for a variable of an unnamed struct type instead of handing that type to the JIT, which would build invalid IR from it. On an AddressSanitizer build, which gives those variables unnamed struct types, a JIT-compiled query now fails with ERROR: variable TypeSizeT in llvmjit_types.c is not of its declared type instead of crashing or hanging the backend. The next commit makes it work. --- src/backend/jit/llvm/llvmjit.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 957ab4751b5..aea7d9b9989 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -432,6 +432,15 @@ llvm_pg_var_type(const char *varname) typ = LLVMGlobalGetValueType(v_srcvar); + /* + * 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. + * Using it would generate invalid IR, so refuse it. + */ + if (LLVMGetTypeKind(typ) == LLVMStructTypeKind && LLVMIsLiteralStruct(typ)) + elog(ERROR, "variable %s in llvmjit_types.c is not of its declared type", + varname); + return typ; } -- 2.54.0 (Apple Git-157)