Skip to content

Commit 889dfd4

Browse files
authored
[libc][msan] Fix "non-constexpr function '__msan_unpoison' cannot be used in a constant expression" (#88719)
Prior to this patch, calling `cpp::bit_cast<T>` in `constexpr` expressions under `-fsanitize=memory` would fail with the following message "non-constexpr function '__msan_unpoison' cannot be used in a constant expression". This patch makes sure that the `__msan_unpoison` expression is guarded by `!__builtin_is_constant_evaluated()`.
1 parent 9f3334e commit 889dfd4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

libc/src/__support/macros/sanitizer.h

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

50-
#if defined(LIBC_HAVE_MEMORY_SANITIZER) && __has_builtin(__builtin_constant_p)
50+
#if defined(LIBC_HAVE_MEMORY_SANITIZER)
5151
// Only perform MSAN unpoison in non-constexpr context.
5252
#include <sanitizer/msan_interface.h>
5353
#define MSAN_UNPOISON(addr, size) \
5454
do { \
55-
if (!__builtin_constant_p(*addr)) { \
55+
if (!__builtin_is_constant_evaluated()) \
5656
__msan_unpoison(addr, size); \
57-
} \
5857
} while (0)
5958
#else
6059
#define MSAN_UNPOISON(ptr, size)

0 commit comments

Comments
 (0)