[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
Ming-Yi Lai via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 25 20:22:37 PDT 2024
================
@@ -224,6 +225,34 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
else
Builder.defineMacro("__riscv_32e");
}
+
+ if (Opts.CFProtectionBranch) {
+ if (checkCFProtectionBranchSupported()) {
+ auto Scheme = Opts.getCFBranchLabelScheme();
+ if (checkCFBranchLabelSchemeSupported(Scheme)) {
+ if (Scheme == CFBranchLabelSchemeKind::Default)
+ Scheme = getDefaultCFBranchLabelScheme();
+
+ Builder.defineMacro("__riscv_landing_pad", "1");
+ switch (Scheme) {
+ case CFBranchLabelSchemeKind::Unlabeled:
+ Builder.defineMacro("__riscv_landing_pad_unlabeled", "1");
+ break;
+ case CFBranchLabelSchemeKind::FuncSig:
+ Builder.defineMacro("__riscv_landing_pad_func_sig", "1");
+ break;
+ case CFBranchLabelSchemeKind::Default:
+ llvm_unreachable("default cf-branch-label scheme should already be "
+ "transformed to other scheme");
+ }
+ } else
+ Diags.Report(diag::err_opt_not_valid_on_target)
+ << (Twine("-mcf-branch-label-scheme=") +
+ getCFBranchLabelSchemeFlagVal(Scheme))
+ .str();
+ } else
+ Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
----------------
mylai-mtk wrote:
Yes, if it's `clang -c` or `clang -S`, I believe it would be diagnosed in `CodeGenModule`, but if it's `clang -E -dM`, it wouldn't be diagnosed, since code gen is not required.
https://github.com/llvm/llvm-project/pull/109600
More information about the cfe-commits
mailing list