[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 25 11:55:22 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";
----------------
topperc wrote:

Won't this get diagnosed later in CodeGenModule anyway?

https://github.com/llvm/llvm-project/pull/109600


More information about the cfe-commits mailing list