[clang] 8e1530b - [Driver] Simplify OPT_fcolor_diagnostics claim
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 10 01:21:36 PDT 2022
Author: Fangrui Song
Date: 2022-04-10T01:21:31-07:00
New Revision: 8e1530ba43f0e298c3e4821f38434479baf88227
URL: https://github.com/llvm/llvm-project/commit/8e1530ba43f0e298c3e4821f38434479baf88227
DIFF: https://github.com/llvm/llvm-project/commit/8e1530ba43f0e298c3e4821f38434479baf88227.diff
LOG: [Driver] Simplify OPT_fcolor_diagnostics claim
Mostly NFC, but the diagnostic is changed to the more appropriate
err_drv_invalid_argument_to_option.
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/color-diagnostics.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 0da0c75d0cc5d..c0566189ae69c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3954,20 +3954,13 @@ static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args,
// re-parsed to construct this job; claim any possible color diagnostic here
// to avoid warn_drv_unused_argument and diagnose bad
// OPT_fdiagnostics_color_EQ values.
- for (const Arg *A : Args) {
- const Option &O = A->getOption();
- if (!O.matches(options::OPT_fcolor_diagnostics) &&
- !O.matches(options::OPT_fno_color_diagnostics) &&
- !O.matches(options::OPT_fdiagnostics_color_EQ))
- continue;
-
- if (O.matches(options::OPT_fdiagnostics_color_EQ)) {
- StringRef Value(A->getValue());
- if (Value != "always" && Value != "never" && Value != "auto")
- D.Diag(diag::err_drv_clang_unsupported)
- << ("-fdiagnostics-color=" + Value).str();
- }
- A->claim();
+ Args.getLastArg(options::OPT_fcolor_diagnostics,
+ options::OPT_fno_color_diagnostics);
+ if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
+ StringRef Value(A->getValue());
+ if (Value != "always" && Value != "never" && Value != "auto")
+ D.Diag(diag::err_drv_invalid_argument_to_option)
+ << Value << A->getOption().getName();
}
if (D.getDiags().getDiagnosticOptions().ShowColors)
diff --git a/clang/test/Driver/color-diagnostics.c b/clang/test/Driver/color-diagnostics.c
index ebf614eeb1a37..0d38a6ba2d414 100644
--- a/clang/test/Driver/color-diagnostics.c
+++ b/clang/test/Driver/color-diagnostics.c
@@ -29,7 +29,7 @@
// RUN: %clang -fdiagnostics-color=foo -### -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-DCE_FOO %s
-// CHECK-DCE_FOO: error: the clang compiler does not support '-fdiagnostics-color=foo'
+// CHECK-DCE_FOO: error: invalid argument 'foo' to -fdiagnostics-color=
// Check that the last flag wins.
// RUN: %clang -fno-color-diagnostics -fdiagnostics-color -### -c %s 2>&1 \
More information about the cfe-commits
mailing list