[PATCH] D96274: [clang][cli] Generate and round-trip Diagnostic options

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 11:26:31 PST 2021


dexonsmith requested changes to this revision.
dexonsmith added inline comments.
This revision now requires changes to proceed.


================
Comment at: clang/lib/Frontend/CompilerInvocation.cpp:745
+
+    A->render(Args, Rendered);
   }
----------------
It's not obvious why this renders the args instead of calling `A->getAsString()` to get the literal command-line argument and putting it directly in DiagnosticsAsWritten. If that'll work, I suggest switching to that, since it's a bit more straightforward; if there's some reason you can't do that, please leave a comment explaining why.


================
Comment at: clang/lib/Frontend/CompilerInvocation.cpp:2230-2240
+  for (const auto &Warning : Opts.WarningsAsWritten) {
+    // This option also maps to UndefPrefixes that generates it automatically.
+    if (StringRef(Warning).startswith("-Wundef-prefix="))
+      continue;
+    // TODO: Consider ignoring '-Wno-rewrite-macros' that maps to
+    // NoRewriteMacros.
+    Args.push_back(SA(Warning));
----------------
Does this mean that if some client is programmatically modifying the `Warnings` array (which is what `CompilerInstance` reads) they need to also update `WarningsAsWritten` array identically to get command-line generation to work?

If so, then this is a bit non-obvious / error-prone. Maybe these can encapsulated together:
```
struct DiagnosticArg {
  std::string Name;
  std::string AsWritten;
};
std::vector<DiagnosticArg> Warnings;
std::vector<DiagnosticArg> Remarks;
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96274/new/

https://reviews.llvm.org/D96274



More information about the cfe-commits mailing list