Fix Clang 21+ `-Wuninitialized-const-pointer` warning when using MSan
What changed, and why it matters
This is a build-system hygiene patch that suppresses a compiler warning in test-only sanitizer code. It does not change runtime behavior, fix a vulnerability, or affect how Bitcoin/crypto operations work. The change only tells Clang 21+ to ignore a new warning when using MemorySanitizer during tests.
No security action required. Treat as normal build cleanup. Reviewers may verify the pragma version gate matches the affected Clang releases.
Security signals we found
No security signal present
Change is purely diagnostic/warning suppression
No functional code or cryptographic logic modified
Evidence from the diff
The commit modifies src/checkmem.h to wrap __msan_allocated_memory() in a pragma that disables Clang 21+’s -Wuninitialized-const-pointer warning. SECP256K1_CHECKMEM_UNDEFINE is used in MemorySanitizer builds to mark memory as uninitialized for testing purposes. The macro’s functional behavior is identical; only diagnostic suppression is added for a specific compiler version range.
Changed components
src/checkmem.hMemorySanitizer test builds with Clang 21+Inspect captured patch +11 / −1
diff --git a/src/checkmem.h b/src/checkmem.h
index 7e333ce..08eae47 100644
--- a/src/checkmem.h
+++ b/src/checkmem.h
@@ -48,7 +48,17 @@
# if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# define SECP256K1_CHECKMEM_ENABLED 1
-# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len))
+# if defined(__clang__) && ((__clang_major__ == 21 && __clang_minor__ >= 1) || __clang_major__ >= 22)
+# define SECP256K1_CHECKMEM_UNDEFINE(p, len) do { \
+ /* Work around https://github.com/llvm/llvm-project/issues/160094 */ \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wuninitialized-const-pointer\"") \
+ __msan_allocated_memory((p), (len)); \
+ _Pragma("clang diagnostic pop") \
+ } while(0)
+# else
+# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len))
+# endif
# define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len))
# define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) __msan_unpoison((p), (len))
# define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len))
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.