[libc-commits] [libc] [libc][msan] Fix "non-constexpr function '__msan_unpoison' cannot be used in a constant expression" (PR #88719)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Mon Apr 15 11:54:12 PDT 2024
================
@@ -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\""); \
----------------
nickdesaulniers wrote:
I think if you simply remove the `constexpr` from the `if constexpr` (L61), then you will no longer observe the warning, making the pragmas unnecessary.
https://godbolt.org/z/jfPzEonKd
https://github.com/llvm/llvm-project/pull/88719
More information about the libc-commits
mailing list