Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Only perform MSAN unpoison in non-constexpr context. #72299

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

lntue
Copy link
Contributor

@lntue lntue commented Nov 14, 2023

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 14, 2023

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/72299.diff

1 Files Affected:

  • (modified) libc/src/__support/macros/sanitizer.h (+9-2)
diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
index 6989672b4839d20..fc66c2005c42de7 100644
--- a/libc/src/__support/macros/sanitizer.h
+++ b/libc/src/__support/macros/sanitizer.h
@@ -47,9 +47,16 @@
 // Functions to unpoison memory
 //-----------------------------------------------------------------------------
 
-#ifdef LIBC_HAVE_MEMORY_SANITIZER
+#if defined(LIBC_HAVE_MEMORY_SANITIZER) &&                                     \
+    LIBC_HAS_BUILTIN(__builtin_constant_p)
+// Only perform MSAN unpoison in non-constexpr context.
 #include <sanitizer/msan_interface.h>
-#define MSAN_UNPOISON(addr, size) __msan_unpoison(addr, size)
+#define MSAN_UNPOISON(addr, size)                                              \
+  do {                                                                         \
+    if (!__builtin_constant_p(*addr)) {                                        \
+      __msan_unpoison(addr, size);                                             \
+    }                                                                          \
+  } while (0)
 #else
 #define MSAN_UNPOISON(ptr, size)
 #endif

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lntue lntue merged commit 0177c1c into llvm:main Nov 14, 2023
4 checks passed
@lntue lntue deleted the msan branch November 15, 2023 06:17
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants