[libc-commits] [libc] [libc] Prefix sanitizer macros with LIBC_ (PR #205002)

Nico Weber via libc-commits libc-commits at lists.llvm.org
Sun Jun 21 11:28:10 PDT 2026


https://github.com/nico created https://github.com/llvm/llvm-project/pull/205002

Since these macros leak into user code via libc/shared/math.h,
prefix them with LIBC_ to not cause collisions.

Change created with:

    rg -l MSAN_UNPOISON libc | xargs sed -i '' \
        -e 's/MSAN_UNPOISON/LIBC_MSAN_UNPOISON/g'
    rg -l ASAN_POISON_MEMORY_REGION libc | xargs sed -i '' -e \
        's/ASAN_POISON_MEMORY_REGION/LIBC_ASAN_POISON_MEMORY_REGION/g'
    rg -l ASAN_POISON_MEMORY_REGION libc | xargs sed -i '' -e \
        's/ASAN_POISON_MEMORY_REGION/LIBC_ASAN_POISON_MEMORY_REGION/g'

No behavior change.

>From 9d2624fb1034adc7c43d9e19f9cbdf9275be2432 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 21 Jun 2026 14:25:10 -0400
Subject: [PATCH 1/2] [libc] Prefix sanitizer macros with LIBC_

Since these macros leak into user code via libc/shared/math.h,
prefix them with LIBC_ to not cause collisions.

Change created with:

    rg -l MSAN_UNPOISON libc | xargs sed -i '' \
        -e 's/MSAN_UNPOISON/LIBC_MSAN_UNPOISON/g'
    rg -l ASAN_POISON_MEMORY_REGION libc | xargs sed -i '' -e \
        's/ASAN_POISON_MEMORY_REGION/LIBC_ASAN_POISON_MEMORY_REGION/g'
    rg -l ASAN_POISON_MEMORY_REGION libc | xargs sed -i '' -e \
        's/ASAN_POISON_MEMORY_REGION/LIBC_ASAN_POISON_MEMORY_REGION/g'

No behavior change.
---
 libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h    |  6 +++---
 libc/src/__support/macros/sanitizer.h                | 12 ++++++------
 libc/src/sys/epoll/linux/epoll_pwait.cpp             |  2 +-
 libc/src/sys/epoll/linux/epoll_pwait2.cpp            |  2 +-
 libc/src/sys/epoll/linux/epoll_wait.cpp              |  2 +-
 libc/src/sys/socket/linux/recv.cpp                   |  2 +-
 libc/src/sys/socket/linux/recvfrom.cpp               |  4 ++--
 libc/src/sys/socket/linux/recvmsg.cpp                |  8 ++++----
 libc/src/sys/socket/linux/socketpair.cpp             |  2 +-
 libc/src/unistd/linux/pipe.cpp                       |  4 ++--
 libc/src/unistd/linux/pipe2.cpp                      |  2 +-
 libc/src/unistd/linux/pread.cpp                      |  4 ++--
 libc/src/unistd/linux/read.cpp                       |  4 ++--
 .../src/string/memory_utils/memory_check_utils.h     |  4 ++--
 14 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h b/libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h
index a38e4c9988084..eb4c9a8bad1d0 100644
--- a/libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h
+++ b/libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h
@@ -34,7 +34,7 @@ LIBC_INLINE static uint16_t get_x87_control_word() {
   __asm fstcw w;
 #else  // !LIBC_COMPILER_IS_MSVC
   asm volatile("fnstcw %0" : "=m"(w)::);
-  MSAN_UNPOISON(&w, sizeof(w));
+  LIBC_MSAN_UNPOISON(&w, sizeof(w));
 #endif // LIBC_COMPILER_IS_MSVC
 
   return w;
@@ -55,7 +55,7 @@ LIBC_INLINE static uint16_t get_x87_status_word() {
   __asm fnstsw w;
 #else  // !LIBC_COMPILER_IS_MSVC
   asm volatile("fnstsw %0" : "=m"(w)::);
-  MSAN_UNPOISON(&w, sizeof(w));
+  LIBC_MSAN_UNPOISON(&w, sizeof(w));
 #endif // LIBC_COMPILER_IS_MSVC
 
   return w;
@@ -74,7 +74,7 @@ LIBC_INLINE static void get_x87_state_descriptor(X87StateDescriptor &s) {
   __asm fnstenv s;
 #else  // !LIBC_COMPILER_IS_MSVC
   asm volatile("fnstenv %0" : "=m"(s));
-  MSAN_UNPOISON(&s, sizeof(s));
+  LIBC_MSAN_UNPOISON(&s, sizeof(s));
 #endif // LIBC_COMPILER_IS_MSVC
 }
 
diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
index 84268a19abbb4..a374b8a70a78a 100644
--- a/libc/src/__support/macros/sanitizer.h
+++ b/libc/src/__support/macros/sanitizer.h
@@ -26,24 +26,24 @@
 #ifdef LIBC_HAS_MEMORY_SANITIZER
 // Only perform MSAN unpoison in non-constexpr context.
 #include <sanitizer/msan_interface.h>
-#define MSAN_UNPOISON(addr, size)                                              \
+#define LIBC_MSAN_UNPOISON(addr, size)                                              \
   do {                                                                         \
     if (!__builtin_is_constant_evaluated())                                    \
       __msan_unpoison(addr, size);                                             \
   } while (0)
 #else
-#define MSAN_UNPOISON(ptr, size)
+#define LIBC_MSAN_UNPOISON(ptr, size)
 #endif
 
 #ifdef LIBC_HAS_ADDRESS_SANITIZER
 #include <sanitizer/asan_interface.h>
-#define ASAN_POISON_MEMORY_REGION(addr, size)                                  \
+#define LIBC_ASAN_POISON_MEMORY_REGION(addr, size)                                  \
   __asan_poison_memory_region((addr), (size))
-#define ASAN_UNPOISON_MEMORY_REGION(addr, size)                                \
+#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size)                                \
   __asan_unpoison_memory_region((addr), (size))
 #else
-#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
-#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#define LIBC_ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
 #endif
 
 #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
index 24fd1dbdc467d..d0b4cc1bed5ce 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -35,7 +35,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait,
     return -1;
   }
 
-  MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
+  LIBC_MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
 
   return ret;
 }
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index 219984528efdd..ee507344d68d2 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -37,7 +37,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2,
     return -1;
   }
 
-  MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
+  LIBC_MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
 
   return ret;
 }
diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index 7fae7b55992fa..e459ca0e30fe5 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -41,7 +41,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait,
     return -1;
   }
 
-  MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
+  LIBC_MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
 
   return ret;
 }
diff --git a/libc/src/sys/socket/linux/recv.cpp b/libc/src/sys/socket/linux/recv.cpp
index 3c2dfdce7fbab..20b22b5d71470 100644
--- a/libc/src/sys/socket/linux/recv.cpp
+++ b/libc/src/sys/socket/linux/recv.cpp
@@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(ssize_t, recv,
     return -1;
   }
 
-  MSAN_UNPOISON(buf, result.value());
+  LIBC_MSAN_UNPOISON(buf, result.value());
 
   return result.value();
 }
diff --git a/libc/src/sys/socket/linux/recvfrom.cpp b/libc/src/sys/socket/linux/recvfrom.cpp
index 97f1c391711e7..2f9c6f7352301 100644
--- a/libc/src/sys/socket/linux/recvfrom.cpp
+++ b/libc/src/sys/socket/linux/recvfrom.cpp
@@ -42,13 +42,13 @@ LLVM_LIBC_FUNCTION(ssize_t, recvfrom,
   }
 
   ssize_t ret = result.value();
-  MSAN_UNPOISON(buf, ret);
+  LIBC_MSAN_UNPOISON(buf, ret);
 
   if (src_addr) {
     size_t min_src_addr_size = (*addrlen < srcaddr_sz) ? *addrlen : srcaddr_sz;
     (void)min_src_addr_size; // prevent "set but not used" warning
 
-    MSAN_UNPOISON(src_addr, min_src_addr_size);
+    LIBC_MSAN_UNPOISON(src_addr, min_src_addr_size);
   }
   return ret;
 }
diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index e2361e2d40245..ced8961f107be 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -28,13 +28,13 @@ LLVM_LIBC_FUNCTION(ssize_t, recvmsg, (int sockfd, msghdr *msg, int flags)) {
   }
 
   // Unpoison the msghdr, as well as all its components.
-  MSAN_UNPOISON(msg, sizeof(msghdr));
-  MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);
+  LIBC_MSAN_UNPOISON(msg, sizeof(msghdr));
+  LIBC_MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);
 
   for (size_t i = 0; i < msg->msg_iovlen; ++i) {
-    MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
+    LIBC_MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
   }
-  MSAN_UNPOISON(msg->msg_control, msg->msg_controllen);
+  LIBC_MSAN_UNPOISON(msg->msg_control, msg->msg_controllen);
 
   return result.value();
 }
diff --git a/libc/src/sys/socket/linux/socketpair.cpp b/libc/src/sys/socket/linux/socketpair.cpp
index 49445e07fd6e2..bd5171333f770 100644
--- a/libc/src/sys/socket/linux/socketpair.cpp
+++ b/libc/src/sys/socket/linux/socketpair.cpp
@@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, socketpair,
     return -1;
   }
 
-  MSAN_UNPOISON(sv, sizeof(int) * 2);
+  LIBC_MSAN_UNPOISON(sv, sizeof(int) * 2);
 
   return result.value();
 }
diff --git a/libc/src/unistd/linux/pipe.cpp b/libc/src/unistd/linux/pipe.cpp
index b9943c8338056..9b0c97439dd6f 100644
--- a/libc/src/unistd/linux/pipe.cpp
+++ b/libc/src/unistd/linux/pipe.cpp
@@ -12,7 +12,7 @@
 #include "src/__support/common.h"
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
+#include "src/__support/macros/sanitizer.h" // for LIBC_MSAN_UNPOISON
 #include <sys/syscall.h>                    // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
@@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, pipe, (int pipefd[2])) {
   int ret = LIBC_NAMESPACE::syscall_impl<int>(
       SYS_pipe2, reinterpret_cast<long>(pipefd), 0);
 #endif
-  MSAN_UNPOISON(pipefd, sizeof(int) * 2);
+  LIBC_MSAN_UNPOISON(pipefd, sizeof(int) * 2);
   if (ret < 0) {
     libc_errno = -ret;
     return -1;
diff --git a/libc/src/unistd/linux/pipe2.cpp b/libc/src/unistd/linux/pipe2.cpp
index d30f3b37a1adc..baf78ff55be7b 100644
--- a/libc/src/unistd/linux/pipe2.cpp
+++ b/libc/src/unistd/linux/pipe2.cpp
@@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(int, pipe2, (int pipefd[2], int flags)) {
     libc_errno = -ret;
     return -1;
   }
-  MSAN_UNPOISON(pipefd, sizeof(int) * 2);
+  LIBC_MSAN_UNPOISON(pipefd, sizeof(int) * 2);
   return ret;
 }
 
diff --git a/libc/src/unistd/linux/pread.cpp b/libc/src/unistd/linux/pread.cpp
index cf3152dbbad84..782b4c2eb8a0d 100644
--- a/libc/src/unistd/linux/pread.cpp
+++ b/libc/src/unistd/linux/pread.cpp
@@ -13,7 +13,7 @@
 #include "src/__support/common.h"
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
+#include "src/__support/macros/sanitizer.h" // for LIBC_MSAN_UNPOISON
 #include <sys/syscall.h>                    // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
@@ -37,7 +37,7 @@ LLVM_LIBC_FUNCTION(ssize_t, pread,
   }
   // The cast is important since there is a check that dereferences the pointer
   // which fails on void*.
-  MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
+  LIBC_MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
   if (ret < 0) {
     libc_errno = static_cast<int>(-ret);
     return -1;
diff --git a/libc/src/unistd/linux/read.cpp b/libc/src/unistd/linux/read.cpp
index d39627e57a483..b9afe314d170b 100644
--- a/libc/src/unistd/linux/read.cpp
+++ b/libc/src/unistd/linux/read.cpp
@@ -12,7 +12,7 @@
 #include "src/__support/common.h"
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
+#include "src/__support/macros/sanitizer.h" // for LIBC_MSAN_UNPOISON
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) {
   }
   // The cast is important since there is a check that dereferences the pointer
   // which fails on void*.
-  MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
+  LIBC_MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
   return result.value();
 }
 
diff --git a/libc/test/src/string/memory_utils/memory_check_utils.h b/libc/test/src/string/memory_utils/memory_check_utils.h
index c38039ebd3dd4..21c42620e1d0f 100644
--- a/libc/test/src/string/memory_utils/memory_check_utils.h
+++ b/libc/test/src/string/memory_utils/memory_check_utils.h
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
 // This is a utility class to be used by Buffer below, do not use directly.
 struct PoisonedBuffer {
   PoisonedBuffer(size_t size) : ptr((char *)malloc(size)) {
-    ASAN_POISON_MEMORY_REGION(ptr, size);
+    LIBC_ASAN_POISON_MEMORY_REGION(ptr, size);
   }
   ~PoisonedBuffer() { free(ptr); }
 
@@ -47,7 +47,7 @@ struct Buffer : private PoisonedBuffer {
     offset_ptr += distance_to_next_aligned<kAlign>(ptr);
     if (aligned == Aligned::NO)
       ++offset_ptr;
-    ASAN_UNPOISON_MEMORY_REGION(offset_ptr, size);
+    LIBC_ASAN_UNPOISON_MEMORY_REGION(offset_ptr, size);
   }
   cpp::span<char> span() { return cpp::span<char>(offset_ptr, size); }
 

>From 5ca7d63e8dda10e6da8a7cdceb39e1e4ce49d2fb Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 21 Jun 2026 14:27:42 -0400
Subject: [PATCH 2/2] git clang-format main

---
 libc/src/__support/macros/sanitizer.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
index a374b8a70a78a..abed7a20a35b8 100644
--- a/libc/src/__support/macros/sanitizer.h
+++ b/libc/src/__support/macros/sanitizer.h
@@ -26,7 +26,7 @@
 #ifdef LIBC_HAS_MEMORY_SANITIZER
 // Only perform MSAN unpoison in non-constexpr context.
 #include <sanitizer/msan_interface.h>
-#define LIBC_MSAN_UNPOISON(addr, size)                                              \
+#define LIBC_MSAN_UNPOISON(addr, size)                                         \
   do {                                                                         \
     if (!__builtin_is_constant_evaluated())                                    \
       __msan_unpoison(addr, size);                                             \
@@ -37,13 +37,14 @@
 
 #ifdef LIBC_HAS_ADDRESS_SANITIZER
 #include <sanitizer/asan_interface.h>
-#define LIBC_ASAN_POISON_MEMORY_REGION(addr, size)                                  \
+#define LIBC_ASAN_POISON_MEMORY_REGION(addr, size)                             \
   __asan_poison_memory_region((addr), (size))
-#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size)                                \
+#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size)                           \
   __asan_unpoison_memory_region((addr), (size))
 #else
 #define LIBC_ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
-#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#define LIBC_ASAN_UNPOISON_MEMORY_REGION(addr, size)                           \
+  ((void)(addr), (void)(size))
 #endif
 
 #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H



More information about the libc-commits mailing list