aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/InitPreprocessor.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2025-08-15 16:13:23 -0700
committerGitHub <noreply@github.com>2025-08-15 16:13:23 -0700
commit568c23bbd3303518c5056d7f03444dae4fdc8a9c (patch)
tree35a06e463404efaa158e9f0d3222239369de9378 /clang/lib/Frontend/InitPreprocessor.cpp
parentbe0135538a934f108a6fb70f93ec587be3016033 (diff)
downloadllvm-568c23bbd3303518c5056d7f03444dae4fdc8a9c.zip
llvm-568c23bbd3303518c5056d7f03444dae4fdc8a9c.tar.gz
llvm-568c23bbd3303518c5056d7f03444dae4fdc8a9c.tar.bz2
Frontend: Define __SANITIZE_*__ macros for certain sanitizers.
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. The rationale is that __has_feature is only really meant for standardized features (see the comment at the top of clang/include/clang/Basic/Features.def), and __has_extension has the issues discovered as part of #153104. Let's start by defining macros for ASan, HWASan and TSan, consistently with gcc. Reviewers: vitalybuka, ojhunt, AaronBallman, fmayer Reviewed By: fmayer, vitalybuka Pull Request: https://github.com/llvm/llvm-project/pull/153888
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 008a35d..5980806 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();