[all-commits] [llvm/llvm-project] 555a81: [clang] NFC: Extract DiagnosticOptions parsing

Jan Svoboda via All-commits all-commits at lists.llvm.org
Thu Sep 2 05:37:27 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 555a817d1dac5d88fdb445cd7c93cf66b769bc37
      https://github.com/llvm/llvm-project/commit/555a817d1dac5d88fdb445cd7c93cf66b769bc37
  Author: Jan Svoboda <jan_svoboda at apple.com>
  Date:   2021-09-02 (Thu, 02 Sep 2021)

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

  Log Message:
  -----------
  [clang] NFC: Extract DiagnosticOptions parsing

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, essentially 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 reusable function: `CreateAndPopulateDiagOpts`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D108918




More information about the All-commits mailing list