llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Peter Collingbourne (pcc)

<details>
<summary>Changes</summary>

Per discussion with @<!-- -->ojhunt and @<!-- -->AaronBallman we are moving 
towards
predefined macros and away from __has_feature and __has_extension for
detecting sanitizers and other similar features. Let's start by defining
macros for ASan, HWASan and TSan, consistently with gcc.


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


2 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+7) 
- (added) clang/test/Preprocessor/sanitizer-predefines.c (+8) 


``````````diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 008a35d5265e1..81d798d8e27c6 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1519,6 +1519,13 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   if (TI.getTriple().isOSBinFormatELF())
     Builder.defineMacro("__ELF__");
 
+  if (LangOpts.Sanitize.has(SanitizerKind::Address))
+    Builder.defineMacro("__SANITIZE_ADDRESS__");
+  if (LangOpts.Sanitize.has(SanitizerKind::HWAddress))
+    Builder.defineMacro("__SANITIZE_HWADDRESS__");
+  if (LangOpts.Sanitize.has(SanitizerKind::Thread))
+    Builder.defineMacro("__SANITIZE_THREAD__");
+  
   // Target OS macro definitions.
   if (PPOpts.DefineTargetOSMacros) {
     const llvm::Triple &Triple = TI.getTriple();
diff --git a/clang/test/Preprocessor/sanitizer-predefines.c 
b/clang/test/Preprocessor/sanitizer-predefines.c
new file mode 100644
index 0000000000000..9d2f6bf2517a2
--- /dev/null
+++ b/clang/test/Preprocessor/sanitizer-predefines.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -E -dM -triple aarch64-unknown-linux -fsanitize=address %s 
| FileCheck %s --check-prefix=ASAN
+// ASAN: #define __SANITIZE_ADDRESS__ 1
+
+// RUN: %clang_cc1 -E -dM -triple aarch64-unknown-linux -fsanitize=hwaddress 
%s | FileCheck %s --check-prefix=HWASAN
+// HWASAN: #define __SANITIZE_HWADDRESS__ 1
+
+// RUN: %clang_cc1 -E -dM -triple aarch64-unknown-linux -fsanitize=thread %s | 
FileCheck %s --check-prefix=TSAN
+// TSAN: #define __SANITIZE_THREAD__ 1

``````````

</details>


https://github.com/llvm/llvm-project/pull/153888
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to