[libc-commits] [libc] 6473009 - [libc][NFC] Move sanitizer to macros folder

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Tue Feb 7 03:13:55 PST 2023


Author: Guillaume Chatelet
Date: 2023-02-07T11:13:43Z
New Revision: 6473009502e20ba0f861f13cc1bccffcc17c5161

URL: https://github.com/llvm/llvm-project/commit/6473009502e20ba0f861f13cc1bccffcc17c5161
DIFF: https://github.com/llvm/llvm-project/commit/6473009502e20ba0f861f13cc1bccffcc17c5161.diff

LOG: [libc][NFC] Move sanitizer to macros folder

Added: 
    libc/src/__support/macros/sanitizer.h

Modified: 
    libc/src/__support/CMakeLists.txt
    libc/src/__support/FPUtil/x86_64/FEnvImpl.h
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    libc/src/__support/sanitizer.h


################################################################################
diff  --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 78e301830850..b6f934c5e233 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -23,7 +23,7 @@ add_header_library(
 add_header_library(
   sanitizer
   HDRS
-    sanitizer.h
+    macros/sanitizer.h
   DEPENDS
     libc.src.__support.compiler_features
 )

diff  --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
index d80fa5ba9a22..bf633f4fcc85 100644
--- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
@@ -18,7 +18,7 @@
 #include <fenv.h>
 #include <stdint.h>
 
-#include "src/__support/sanitizer.h"
+#include "src/__support/macros/sanitizer.h"
 
 namespace __llvm_libc {
 namespace fputil {

diff  --git a/libc/src/__support/macros/sanitizer.h b/libc/src/__support/macros/sanitizer.h
new file mode 100644
index 000000000000..5337c08d3599
--- /dev/null
+++ b/libc/src/__support/macros/sanitizer.h
@@ -0,0 +1,56 @@
+//===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H
+#define LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H
+
+#include "src/__support/macros/compiler_features.h"
+
+//-----------------------------------------------------------------------------
+// Properties to check the presence or absence or sanitizers
+//-----------------------------------------------------------------------------
+
+// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
+// a compiler instrumentation module and a run-time library. The
+// MEMORY_SANITIZER macro is deprecated but we will continue to honor it for
+// now.
+#ifdef LIBC_HAVE_MEMORY_SANITIZER
+#error "LIBC_HAVE_MEMORY_SANITIZER cannot be directly set."
+#elif defined(MEMORY_SANITIZER) || defined(__SANITIZE_MEMORY__) ||             \
+    (LLVM_LIBC_HAS_FEATURE(memory_sanitizer) && !defined(__native_client__))
+#define LIBC_HAVE_MEMORY_SANITIZER
+#endif
+
+// AddressSanitizer (ASan) is a fast memory error detector. The
+// ADDRESS_SANITIZER macro is deprecated but we will continue to honor it for
+// now.
+#ifdef LIBC_HAVE_ADDRESS_SANITIZER
+#error "LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set."
+#elif defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__) ||           \
+    LLVM_LIBC_HAS_FEATURE(address_sanitizer)
+#define LIBC_HAVE_ADDRESS_SANITIZER
+#endif
+
+// HWAddressSanitizer (HWASan) is a fast, low memory overhead error detector.
+#ifdef LIBC_HAVE_HWADDRESS_SANITIZER
+#error "LIBC_HAVE_HWADDRESS_SANITIZER cannot be directly set."
+#elif LLVM_LIBC_HAS_FEATURE(hwaddress_sanitizer)
+#define LIBC_HAVE_HWADDRESS_SANITIZER
+#endif
+
+//-----------------------------------------------------------------------------
+// Functions to unpoison memory
+//-----------------------------------------------------------------------------
+
+#if LIBC_HAVE_MEMORY_SANITIZER
+#include <sanitizer/msan_interface.h>
+#define SANITIZER_MEMORY_INITIALIZED(addr, size) __msan_unpoison(addr, size)
+#else
+#define SANITIZER_MEMORY_INITIALIZED(ptr, size)
+#endif
+#endif // LLVM_LIBC_SRC_SUPPORT_MACROS_SANITIZER_H

diff  --git a/libc/src/__support/sanitizer.h b/libc/src/__support/sanitizer.h
deleted file mode 100644
index 47c130eea97e..000000000000
--- a/libc/src/__support/sanitizer.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_SUPPORT_SANITIZER_H
-#define LLVM_LIBC_SRC_SUPPORT_SANITIZER_H
-
-#include "src/__support/macros/compiler_features.h"
-
-// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
-// a compiler instrumentation module and a run-time library.
-#ifdef LLVM_LIBC_HAVE_MEMORY_SANITIZER
-#error "LLVM_LIBC_HAVE_MEMORY_SANITIZER cannot be directly set."
-#elif defined(MEMORY_SANITIZER)
-// The MEMORY_SANITIZER macro is deprecated but we will continue to honor it
-// for now.
-#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1
-#elif defined(__SANITIZE_MEMORY__)
-#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1
-#elif !defined(__native_client__) && LLVM_LIBC_HAS_FEATURE(memory_sanitizer)
-#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1
-#endif
-
-// AddressSanitizer (ASan) is a fast memory error detector.
-#ifdef LLVM_LIBC_HAVE_ADDRESS_SANITIZER
-#error "LLVM_LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set."
-#elif defined(ADDRESS_SANITIZER)
-// The ADDRESS_SANITIZER macro is deprecated but we will continue to honor it
-// for now.
-#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1
-#elif defined(__SANITIZE_ADDRESS__)
-#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1
-#elif LLVM_LIBC_HAS_FEATURE(address_sanitizer)
-#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1
-#endif
-
-// HWAddressSanitizer (HWASan) is a fast, low memory overhead error detector.
-#ifdef LLVM_LIBC_HAVE_HWADDRESS_SANITIZER
-#error "LLVM_LIBC_HAVE_HWADDRESS_SANITIZER cannot be directly set."
-#elif LLVM_LIBC_HAS_FEATURE(hwaddress_sanitizer)
-#define LLVM_LIBC_HAVE_HWADDRESS_SANITIZER 1
-#endif
-
-#if LLVM_LIBC_HAVE_MEMORY_SANITIZER
-#include <sanitizer/msan_interface.h>
-#define SANITIZER_MEMORY_INITIALIZED(addr, size) __msan_unpoison(addr, size)
-#else
-#define SANITIZER_MEMORY_INITIALIZED(ptr, size)
-#endif
-
-#endif // LLVM_LIBC_SRC_SUPPORT_SANITIZER_H

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index dbfb31ca083a..5637536e23fe 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -67,7 +67,7 @@ libc_support_library(
 
 libc_support_library(
     name = "__support_sanitizer",
-    hdrs = ["src/__support/sanitizer.h"],
+    hdrs = ["src/__support/macros/sanitizer.h"],
     deps = [
         ":__support_compiler_features",
         ":libc_root",


        


More information about the libc-commits mailing list