[libc-commits] [libc] [libc][msan] Fix "non-constexpr function '__msan_unpoison' cannot be used in a constant expression" (PR #88719)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Tue Apr 16 05:09:23 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\"");              \
----------------
gchatelet wrote:

I was under the impression that `constexpr` was necessary here but it seems that Clang is happy without it, this vastly simplifies this patch : ) I checked that it also fixes the downstream issue.

https://github.com/llvm/llvm-project/pull/88719


More information about the libc-commits mailing list