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

via libc-commits libc-commits at lists.llvm.org
Tue Nov 14 11:01:44 PST 2023


Author: lntue
Date: 2023-11-14T14:01:35-05:00
New Revision: 0177c1c44353229f74ced98433822efc0441cb48

URL: https://github.com/llvm/llvm-project/commit/0177c1c44353229f74ced98433822efc0441cb48
DIFF: https://github.com/llvm/llvm-project/commit/0177c1c44353229f74ced98433822efc0441cb48.diff

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

Added: 
    

Modified: 
    libc/src/__support/macros/sanitizer.h

Removed: 
    


################################################################################
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