[PATCH] D135389: [Clang] Emit a warning for ambiguous joined '-o' arguments
Joseph Huber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 6 13:41:50 PDT 2022
jhuber6 updated this revision to Diff 465862.
jhuber6 added a comment.
Adjusting check to ensure that this only applies for an edit length of zero once the `-` is added. Also adding a negative check line for other inputs.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135389/new/
https://reviews.llvm.org/D135389
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/unknown-arg.c
Index: clang/test/Driver/unknown-arg.c
===================================================================
--- clang/test/Driver/unknown-arg.c
+++ clang/test/Driver/unknown-arg.c
@@ -64,3 +64,10 @@
// RUN: %clang -S %s -o %t.s -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
// IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+
+// RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \
+// RUN: -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s
+// O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'?
+// O-WARN-NEXT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
+// O-WARN-NEXT: warning: joined argument treated as '-o utput'; did you mean '--output'?
+// O-WARN-NOT: warning: joined argument treated as '-o ffload-device-only'; did you mean '--offload-device-only'?
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@
DiagnosticsEngine::Warning;
}
+ for (const Arg *A : Args.filtered(options::OPT_o)) {
+ if (ArgStrings[A->getIndex()] == A->getSpelling())
+ continue;
+
+ // Warn on joined arguments that are similar to a long argument.
+ std::string ArgString = ArgStrings[A->getIndex()];
+ std::string Nearest;
+ if (getOpts().findNearest("-" + ArgString, Nearest, IncludedFlagsBitmask,
+ ExcludedFlagsBitmask) == 0)
+ Diags.Report(diag::warn_drv_potentially_misspelled_joined_argument)
+ << A->getAsString(Args) << Nearest;
+ }
+
return Args;
}
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -253,6 +253,9 @@
"support for '/Yc' with more than one source file not implemented yet; flag ignored">,
InGroup<ClangClPch>;
+def warn_drv_potentially_misspelled_joined_argument : Warning<
+ "joined argument treated as '%0'; did you mean '%1'?">, InGroup<UnknownArgument>;
+
def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
def err_drv_invalid_value_with_suggestion : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135389.465862.patch
Type: text/x-patch
Size: 2525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221006/ea73d7a1/attachment.bin>
More information about the cfe-commits
mailing list