From 47e0cbf91beed4d561aef7c6f6b5b69f7d071f03 Mon Sep 17 00:00:00 2001
From: Henson Choi <assam258@gmail.com>
Date: Mon, 26 Oct 2026 11:00:20 +0900
Subject: [PATCH v4 4/4] Exclude the variables in llvmjit_types.c from
 AddressSanitizer

This is an alternative to the previous commit.  Instead of having
llvm_pg_var_type() take the declared type out of the type that
AddressSanitizer gives each variable in llvmjit_types.c, exclude those
variables from AddressSanitizer instrumentation with a clang attribute
pragma, so that they keep their declared types.  That file is only
ever compiled by clang.  The rest of its bitcode is still
instrumented.

This commit applies with or without the previous one.  With both, the
code that the previous commit added is never reached.
---
 src/backend/jit/llvm/llvmjit_types.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/backend/jit/llvm/llvmjit_types.c b/src/backend/jit/llvm/llvmjit_types.c
index c8a1f841293..faa8a44941c 100644
--- a/src/backend/jit/llvm/llvmjit_types.c
+++ b/src/backend/jit/llvm/llvmjit_types.c
@@ -44,7 +44,14 @@
  * List of types needed for JITing. These have to be non-static, otherwise
  * clang/LLVM will omit them.  As this file will never be linked into
  * anything, that's harmless.
+ *
+ * They are also excluded from AddressSanitizer instrumentation, so that they
+ * keep the types they are declared with.  This file is only ever compiled by
+ * clang, so a clang pragma is fine here.
  */
+#pragma clang attribute push (pg_attribute_no_sanitize_address(), \
+							  apply_to = variable(is_global))
+
 PGFunction	TypePGFunction;
 size_t		TypeSizeT;
 Datum		TypeDatum;
@@ -71,6 +78,8 @@ TupleDescData StructTupleDescData;
 PlanState	StructPlanState;
 MinimalTupleData StructMinimalTupleData;
 
+#pragma clang attribute pop
+
 
 /*
  * To determine which attributes functions need to have (depends e.g. on
-- 
2.54.0 (Apple Git-157)

