From 889dfd4ab35892840f2bd2d6d7fed6fac025e18e Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Wed, 17 Apr 2024 10:04:22 +0200 Subject: [PATCH] [libc][msan] Fix "non-constexpr function '__msan_unpoison' cannot be used in a constant expression" (#88719) Prior to this patch, calling `cpp::bit_cast` 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()`. --- libc/src/__support/macros/sanitizer.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h index bd9b62b7121a..baf44f7996ca 100644 --- a/libc/src/__support/macros/sanitizer.h +++ b/libc/src/__support/macros/sanitizer.h @@ -47,14 +47,13 @@ // Functions to unpoison memory //----------------------------------------------------------------------------- -#if defined(LIBC_HAVE_MEMORY_SANITIZER) && __has_builtin(__builtin_constant_p) +#if defined(LIBC_HAVE_MEMORY_SANITIZER) // Only perform MSAN unpoison in non-constexpr context. #include #define MSAN_UNPOISON(addr, size) \ do { \ - if (!__builtin_constant_p(*addr)) { \ + if (!__builtin_is_constant_evaluated()) \ __msan_unpoison(addr, size); \ - } \ } while (0) #else #define MSAN_UNPOISON(ptr, size)