diff options
author | Peixin Qiao <qiaopeixin@huawei.com> | 2022-06-22 23:56:34 +0800 |
---|---|---|
committer | Peixin Qiao <qiaopeixin@huawei.com> | 2022-06-22 23:56:34 +0800 |
commit | 430841605d49f515b6a671ec772135cf67ca9506 (patch) | |
tree | a4c8414ffdabd890ec5eb4cf323061bf62f453c2 /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | f31ec689b22ae874398fc44c8950e5671cedfa20 (diff) | |
download | llvm-430841605d49f515b6a671ec772135cf67ca9506.zip llvm-430841605d49f515b6a671ec772135cf67ca9506.tar.gz llvm-430841605d49f515b6a671ec772135cf67ca9506.tar.bz2 |
[flang][Driver] Refine _when_ driver diagnostics are formatted
This patch refines //when// driver diagnostics are formatted so that
`flang-new` and `flang-new -fc1` behave consistently with `clang` and
`clang -cc1`, respectively. This change only applies to driver diagnostics.
Scanning, parsing and semantic diagnostics are separate and not covered here.
**NEW BEHAVIOUR**
To illustrate the new behaviour, consider the following input file:
```! file.f90
program m
integer :: i = k
end
```
In the following invocations, "error: Semantic errors in file.f90" _will be_
formatted:
```
$ flang-new file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
integer :: i = k
$ flang-new -fc1 -fcolor-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
integer :: i = k
```
However, in the following invocations, "error: Semantic errors in file.f90"
_will not be_ formatted:
```
$ flang-new -fno-color-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
integer :: i = k
$ flang-new -fc1 file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
integer :: i = k
```
Before this change, none of the above would be formatted. Note also that the
default behaviour in `flang-new` is different to `flang-new -fc1` (this is
consistent with Clang).
**NOTES ON IMPLEMENTATION**
Note that the diagnostic options are parsed in `createAndPopulateDiagOpt`s in
driver.cpp. That's where the driver's `DiagnosticEngine` options are set. Like
most command-line compiler driver options, these flags are "claimed" in
Flang.cpp (i.e. when creating a frontend driver invocation) by calling
`getLastArg` rather than in driver.cpp.
In Clang's Options.td, `defm color_diagnostics` is replaced with two separate
definitions: `def fcolor_diagnostics` and def fno_color_diagnostics`. That's
because originally `color_diagnostics` derived from `OptInCC1FFlag`, which is a
multiclass for opt-in options in CC1. In order to preserve the current
behaviour in `clang -cc1` (i.e. to keep `-fno-color-diagnostics` unavailable in
`clang -cc1`) and to implement similar behaviour in `flang-new -fc1`, we can't
re-use `OptInCC1FFlag`.
Formatting is only available in consoles that support it and will normally mean that
the message is printed in bold + color.
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
Reviewed By: rovka
Differential Revision: https://reviews.llvm.org/D126164
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 8f2167b..f665daf 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -53,10 +53,11 @@ CompilerInvocationBase::~CompilerInvocationBase() = default; //===----------------------------------------------------------------------===// // Deserialization (from args) //===----------------------------------------------------------------------===// -static bool parseShowColorsArgs( - const llvm::opt::ArgList &args, bool defaultColor) { - // Color diagnostics default to auto ("on" if terminal supports) in the driver - // but default to off in cc1, needing an explicit OPT_fdiagnostics_color. +static bool parseShowColorsArgs(const llvm::opt::ArgList &args, + bool defaultColor = true) { + // Color diagnostics default to auto ("on" if terminal supports) in the + // compiler driver `flang-new` but default to off in the frontend driver + // `flang-new -fc1`, needing an explicit OPT_fdiagnostics_color. // Support both clang's -f[no-]color-diagnostics and gcc's // -f[no-]diagnostics-colors[=never|always|auto]. enum { @@ -88,9 +89,8 @@ static bool parseShowColorsArgs( } bool Fortran::frontend::parseDiagnosticArgs(clang::DiagnosticOptions &opts, - llvm::opt::ArgList &args, - bool defaultDiagColor) { - opts.ShowColors = parseShowColorsArgs(args, defaultDiagColor); + llvm::opt::ArgList &args) { + opts.ShowColors = parseShowColorsArgs(args); return true; } @@ -502,6 +502,10 @@ static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args, } } + // Default to off for `flang-new -fc1`. + res.getFrontendOpts().showColors = + parseShowColorsArgs(args, /*defaultDiagColor=*/false); + return diags.getNumErrors() == numErrorsBefore; } |