[PATCH] D134550: [Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driver
Joseph Huber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 24 05:59:00 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe2213159fa65: [Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driver (authored by jhuber6).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134550/new/
https://reviews.llvm.org/D134550
Files:
clang/lib/Driver/Driver.cpp
clang/test/Driver/debug-options.c
clang/test/Driver/unknown-arg.c
clang/test/Misc/driver-verify.c
Index: clang/test/Misc/driver-verify.c
===================================================================
--- clang/test/Misc/driver-verify.c
+++ 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'?
Index: clang/test/Driver/unknown-arg.c
===================================================================
--- clang/test/Driver/unknown-arg.c
+++ 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'
Index: clang/test/Driver/debug-options.c
===================================================================
--- clang/test/Driver/debug-options.c
+++ 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
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -305,11 +305,17 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134550.462664.patch
Type: text/x-patch
Size: 3207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220924/3e223ea4/attachment.bin>
More information about the cfe-commits
mailing list