[PATCH] D108918: [clang] NFC: Extract DiagnosticOptions parsing

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 30 07:39:10 PDT 2021


jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The way we parse `DiagnosticOptions` is a bit involved.

`DiagnosticOptions` are parsed as part of the cc1-parsing function `CompilerInvocation::CreateFromArgs` which takes `DiagnosticsEngine` as an argument to be able to report errors in command-line arguments. But to create `DiagnosticsEngine`, `DiagnosticOptions` are needed. This is solved by exposing the `ParseDiagnosticArgs` to clients and making its `DiagnosticsEngine` argument optional, essentialy breaking the dependency cycle.

The `ParseDiagnosticArgs` function takes `llvm::opt::ArgList &`, which each client needs to create from the command-line (typically represented as `std::vector<const char *>`). Creating this data structure in this context is somewhat particular. This code pattern is copy-pasted in some places across the upstream code base and also in downstream repos. To make things a bit more uniform, this patch extracts the code into a new function: `CreateAndPopulateDiagOpts`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108918

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/tools/driver/driver.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108918.369442.patch
Type: text/x-patch
Size: 6646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210830/d980a21d/attachment.bin>


More information about the cfe-commits mailing list