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

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 23 10:15:49 PDT 2024


================
@@ -2022,6 +2035,20 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
       Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
   }
 
+  if (const Arg *A = Args.getLastArg(OPT_mcf_branch_label_scheme_EQ)) {
+    if (Opts.CFProtectionBranch) {
+      const StringRef Scheme = A->getValue();
+      if (Scheme == "unlabeled")
+        Opts.setCFBranchLabelScheme(CFBranchLabelSchemeKind::Unlabeled);
+      else if (Scheme == "func-sig")
+        Opts.setCFBranchLabelScheme(CFBranchLabelSchemeKind::FuncSig);
+      else
+        Diags.Report(diag::err_drv_invalid_value)
+            << A->getAsString(Args) << Scheme;
+    } else
+      Diags.Report(diag::warn_drv_unused_argument) << A->getAsString(Args);
----------------
topperc wrote:

If you flip the order of the ifs I thin you'll get the unused argument warning automatically. If you don't call `getLastArg` the argument won't be "claimed"

```
if (Opts.CFProtectionBranch)
  if (const Arg *A = Args.getLastArg(OPT_mcf_branch_label_scheme_EQ)) {

  }
}
```

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


More information about the cfe-commits mailing list