aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Basic/Targets/X86.cpp4
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp11
-rw-r--r--clang/test/Preprocessor/riscv-cf-protection-return.c2
3 files changed, 6 insertions, 11 deletions
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 84a05ce..e4d3ad0 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1109,6 +1109,10 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
if (HasFloat128)
Builder.defineMacro("__SIZEOF_FLOAT128__", "16");
+
+ if (Opts.CFProtectionReturn || Opts.CFProtectionBranch)
+ Builder.defineMacro("__CET__", Twine{(Opts.CFProtectionReturn << 1) |
+ Opts.CFProtectionBranch});
}
bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index b9a5c05..4eb743a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4776,17 +4776,6 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
}
}
- // Add the __CET__ macro if a CFProtection option is set.
- if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
- StringRef Name = A->getValue();
- if (Name == "branch")
- Opts.addMacroDef("__CET__=1");
- else if (Name == "return")
- Opts.addMacroDef("__CET__=2");
- else if (Name == "full")
- Opts.addMacroDef("__CET__=3");
- }
-
// Add macros from the command line.
for (const auto *A : Args.filtered(OPT_D, OPT_U)) {
if (A->getOption().matches(OPT_D))
diff --git a/clang/test/Preprocessor/riscv-cf-protection-return.c b/clang/test/Preprocessor/riscv-cf-protection-return.c
index 3a93a88f..a4cbaa1e 100644
--- a/clang/test/Preprocessor/riscv-cf-protection-return.c
+++ b/clang/test/Preprocessor/riscv-cf-protection-return.c
@@ -40,5 +40,7 @@
// RUN: -menable-experimental-extensions -fcf-protection=full -E -dM %s -o - \
// RUN: | FileCheck --check-prefixes=SHSTK-MACRO %s
+// SHSTK-MACRO-NOT: __CET__
// SHSTK-MACRO: __riscv_shadow_stack 1{{$}}
+// SHSTK-MACRO-NOT: __CET__
// NO-MACRO-NOT: __riscv_shadow_stack