aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2022-10-06 14:50:45 -0500
committerJoseph Huber <jhuber6@vols.utk.edu>2022-10-06 18:20:15 -0500
commit5aba68960719c5d2de9ee0b459def9203e521f5e (patch)
treed3294254c0c05896552287bfb5eca49335f87be8 /clang/lib/Driver/Driver.cpp
parent69695817f5b5bf973c55906afecc825390a6f3ff (diff)
downloadllvm-5aba68960719c5d2de9ee0b459def9203e521f5e.zip
llvm-5aba68960719c5d2de9ee0b459def9203e521f5e.tar.gz
llvm-5aba68960719c5d2de9ee0b459def9203e521f5e.tar.bz2
[Clang] Emit a warning for ambiguous joined '-o' arguments
The offloading toolchain makes heavy use of options beginning with `--o`. This is problematic when combined with the joined `-o` flag. In the following situation, the user will not get the expected output and will not notice as the expected output will still be written. ``` clang++ -x cuda foo.cu -offload-arch=sm_80 -o foo ``` This patch introduces a warning that checks for joined `-o` arguments that would also be a valid driver argument if an additional `-` were added. I believe this situation is uncommon enough to warrant a warning, and can be trivially fixed by the end user by using the more common separate form instead. Reviewed By: tra, MaskRay Differential Revision: https://reviews.llvm.org/D135389
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 21dc180..e612afd 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -327,6 +327,19 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
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;
}