[libc-commits] [libc] [libc][msan] Fix "non-constexpr function '__msan_unpoison' cannot be used in a constant expression" (PR #88719)
via libc-commits
libc-commits at lists.llvm.org
Mon Apr 15 05:06:38 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Guillaume Chatelet (gchatelet)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/88719.diff
1 Files Affected:
- (modified) libc/src/__support/macros/sanitizer.h (+11-4)
``````````diff
diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
index bd9b62b7121a14..9a2fe8c4bcc14d 100644
--- a/libc/src/__support/macros/sanitizer.h
+++ b/libc/src/__support/macros/sanitizer.h
@@ -47,14 +47,21 @@
// Functions to unpoison memory
//-----------------------------------------------------------------------------
-#if defined(LIBC_HAVE_MEMORY_SANITIZER) && __has_builtin(__builtin_constant_p)
-// Only perform MSAN unpoison in non-constexpr context.
+#if defined(LIBC_HAVE_MEMORY_SANITIZER)
+// Only perform MSAN unpoison in non-constexpr context and silence
+// '-Wconstant-evaluated' when MSAN_UNPOISON is called from manifestly constant
+// contexts.
#include <sanitizer/msan_interface.h>
#define MSAN_UNPOISON(addr, size) \
do { \
- if (!__builtin_constant_p(*addr)) { \
+ _Pragma("GCC diagnostic push \"-Wconstant-evaluated\""); \
+ _Pragma("GCC diagnostic ignored \"-Wconstant-evaluated\""); \
+ _Pragma("clang diagnostic push \"-Wconstant-evaluated\""); \
+ _Pragma("clang diagnostic ignored \"-Wconstant-evaluated\""); \
+ if constexpr (!__builtin_is_constant_evaluated()) \
__msan_unpoison(addr, size); \
- } \
+ _Pragma("clang diagnostic pop"); \
+ _Pragma("GCC diagnostic pop"); \
} while (0)
#else
#define MSAN_UNPOISON(ptr, size)
``````````
</details>
https://github.com/llvm/llvm-project/pull/88719
More information about the libc-commits
mailing list