From b0311982e0ff06470d31c54b5d4822fd3c5e19d4 Mon Sep 17 00:00:00 2001
From: Henson Choi <assam258@gmail.com>
Date: Fri, 12 Jun 2026 09:15:10 +0900
Subject: [PATCH v2 2/3] Exclude sanitizer flags from LLVM JIT bitcode
 generation

The meson build passes c_args verbatim to the clang command that emits
the JIT bitcode.  Under -fsanitize=address the instrumentation ends up
in the bitcode and breaks the JIT: any JIT-compiled query crashes the
backend with SIGILL.  The autoconf build is unaffected, as it builds
BITCODE_CFLAGS from a whitelist that never includes CFLAGS.

Filter sanitizer flags out of c_args during bitcode generation.

Author: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewer: Henson Choi <assam258@gmail.com>
---
 src/backend/jit/llvm/meson.build | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build
index 7df8453ad6f..1ebee3bdcaf 100644
--- a/src/backend/jit/llvm/meson.build
+++ b/src/backend/jit/llvm/meson.build
@@ -61,7 +61,23 @@ endif
 
 # XXX: Need to determine proper version of the function cflags for clang
 bitcode_cflags = ['-fno-strict-aliasing', '-fwrapv']
-bitcode_cflags += get_option('c_args')
+
+# Sanitizer instrumentation in the JIT bitcode corrupts the JIT code
+# generator: JIT-compiled queries crash with SIGILL.  Strip sanitizer flags
+# from c_args during bitcode generation, and warn when we do, since the
+# JIT-compiled code then runs without sanitizer coverage.
+bitcode_sanitize_stripped = false
+foreach cflag : get_option('c_args')
+  if cflag.contains('sanitize')
+    bitcode_sanitize_stripped = true
+  else
+    bitcode_cflags += cflag
+  endif
+endforeach
+if bitcode_sanitize_stripped
+  warning('stripping sanitizer flags from LLVM JIT bitcode; JIT-compiled code will not be instrumented')
+endif
+
 bitcode_cflags += cppflags
 
 # XXX: Worth improving on the logic to find directories here
-- 
2.47.3

