[clang] e221315 - [Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driver
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 24 05:58:50 PDT 2022
Author: Joseph Huber
Date: 2022-09-24T07:58:40-05:00
New Revision: e2213159fa654a9ba8b211204a7342f6bc1690c6
URL: https://github.com/llvm/llvm-project/commit/e2213159fa654a9ba8b211204a7342f6bc1690c6
DIFF: https://github.com/llvm/llvm-project/commit/e2213159fa654a9ba8b211204a7342f6bc1690c6.diff
LOG: [Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driver
This patch adds an additional check for if an options passed to the
Clang driver could've been intended for the clang compiler. This is
primarily done for the times when a user attempts to pass an option like
`-ast-dump` to the driver instead.
Reviewed By: MaskRay, aaron.ballman
Differential Revision: https://reviews.llvm.org/D134550
Added:
Modified:
clang/lib/Driver/Driver.cpp
clang/test/Driver/debug-options.c
clang/test/Driver/unknown-arg.c
clang/test/Misc/driver-verify.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d3ab9b7096e2..85c4bb46019fa 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -305,11 +305,17 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
unsigned DiagID;
auto ArgString = A->getAsString(Args);
std::string Nearest;
- if (getOpts().findNearest(
- ArgString, Nearest, IncludedFlagsBitmask, ExcludedFlagsBitmask) > 1) {
- DiagID = IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl
- : diag::err_drv_unknown_argument;
- Diags.Report(DiagID) << ArgString;
+ if (getOpts().findNearest(ArgString, Nearest, IncludedFlagsBitmask,
+ ExcludedFlagsBitmask) > 1) {
+ if (getOpts().findNearest(ArgString, Nearest, options::CC1Option) == 0 &&
+ !IsCLMode()) {
+ DiagID = diag::err_drv_unknown_argument_with_suggestion;
+ Diags.Report(DiagID) << ArgString << "-Xclang " + Nearest;
+ } else {
+ DiagID = IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl
+ : diag::err_drv_unknown_argument;
+ Diags.Report(DiagID) << ArgString;
+ }
} else {
DiagID = IsCLMode()
? diag::warn_drv_unknown_argument_clang_cl_with_suggestion
diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c
index 96c0763fbf9c0..bd13a63162c8e 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -463,6 +463,6 @@
// SIMPLE_TMPL_NAMES: -gsimple-template-names=simple
// FWD_TMPL_PARAMS-DAG: -debug-forward-template-params
// RUN: not %clang -### -target x86_64 -c -g -gsimple-template-names=mangled %s 2>&1 | FileCheck --check-prefix=MANGLED_TEMP_NAMES %s
-// MANGLED_TEMP_NAMES: error: unknown argument: '-gsimple-template-names=mangled'
+// MANGLED_TEMP_NAMES: error: unknown argument '-gsimple-template-names=mangled'; did you mean '-Xclang -gsimple-template-names=mangled'
// RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s
// FULL_TEMP_NAMES-NOT: -gsimple-template-names
diff --git a/clang/test/Driver/unknown-arg.c b/clang/test/Driver/unknown-arg.c
index 45752e9c7976d..32346e3326f3f 100644
--- a/clang/test/Driver/unknown-arg.c
+++ b/clang/test/Driver/unknown-arg.c
@@ -31,7 +31,7 @@
// CHECK: error: unknown argument: '-%d'
// CHECK: error: unknown argument: '-HHHH'
// CHECK: error: unknown argument: '-munknown-to-clang-option'
-// CHECK: error: unknown argument: '-print-stats'
+// CHECK: error: unknown argument '-print-stats'; did you mean '-Xclang -print-stats'?
// CHECK: error: unknown argument: '-funknown-to-clang-option'
// CHECK: error: unknown argument: '-ifoo'
// MULTILIB: warning: argument unused during compilation: '-imultilib dir'
diff --git a/clang/test/Misc/driver-verify.c b/clang/test/Misc/driver-verify.c
index f858a3db85cb5..d03fe1f1f0e81 100644
--- a/clang/test/Misc/driver-verify.c
+++ b/clang/test/Misc/driver-verify.c
@@ -3,4 +3,4 @@
// expected-no-diagnostics
// Test that -verify is strictly rejected as unknown by the driver.
-// CHECK: unknown argument: '-verify'
+// CHECK: unknown argument '-verify'; did you mean '-Xclang -verify'?
More information about the cfe-commits
mailing list