[libc-commits] [libc] [libc] Only perform MSAN unpoison in non-constexpr context. (PR #72299)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 14 10:54:07 PST 2023


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/72299

None

>From 22e157c5d9f3300a0aeef3a33ff4ec142981c635 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 14 Nov 2023 18:51:22 +0000
Subject: [PATCH] [libc] Only perform MSAN unpoison in non-constexpr context.

---
 libc/src/__support/macros/sanitizer.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
index 6989672b4839d20..fc66c2005c42de7 100644
--- a/libc/src/__support/macros/sanitizer.h
+++ b/libc/src/__support/macros/sanitizer.h
@@ -47,9 +47,16 @@
 // Functions to unpoison memory
 //-----------------------------------------------------------------------------
 
-#ifdef LIBC_HAVE_MEMORY_SANITIZER
+#if defined(LIBC_HAVE_MEMORY_SANITIZER) &&                                     \
+    LIBC_HAS_BUILTIN(__builtin_constant_p)
+// Only perform MSAN unpoison in non-constexpr context.
 #include <sanitizer/msan_interface.h>
-#define MSAN_UNPOISON(addr, size) __msan_unpoison(addr, size)
+#define MSAN_UNPOISON(addr, size)                                              \
+  do {                                                                         \
+    if (!__builtin_constant_p(*addr)) {                                        \
+      __msan_unpoison(addr, size);                                             \
+    }                                                                          \
+  } while (0)
 #else
 #define MSAN_UNPOISON(ptr, size)
 #endif



More information about the libc-commits mailing list