Skip to content

Commit 0177c1c

Browse files
authored
[libc] Only perform MSAN unpoison in non-constexpr context. (#72299)
1 parent 410f130 commit 0177c1c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libc/src/__support/macros/sanitizer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@
4747
// Functions to unpoison memory
4848
//-----------------------------------------------------------------------------
4949

50-
#ifdef LIBC_HAVE_MEMORY_SANITIZER
50+
#if defined(LIBC_HAVE_MEMORY_SANITIZER) && \
51+
LIBC_HAS_BUILTIN(__builtin_constant_p)
52+
// Only perform MSAN unpoison in non-constexpr context.
5153
#include <sanitizer/msan_interface.h>
52-
#define MSAN_UNPOISON(addr, size) __msan_unpoison(addr, size)
54+
#define MSAN_UNPOISON(addr, size) \
55+
do { \
56+
if (!__builtin_constant_p(*addr)) { \
57+
__msan_unpoison(addr, size); \
58+
} \
59+
} while (0)
5360
#else
5461
#define MSAN_UNPOISON(ptr, size)
5562
#endif

0 commit comments

Comments
 (0)