-
Notifications
You must be signed in to change notification settings - Fork 15k
[flang][driver] Use -Xflang in diagnostics #164741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang][driver] Use -Xflang in diagnostics #164741
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Tarun Prabhu (tarunprabhu) ChangesWhen an option that is only available in Partially addresses #163550. Full diff: https://github.com/llvm/llvm-project/pull/164741.diff 2 Files Affected:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 40ea513e85427..afaf6c2691ac6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -308,7 +308,16 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
auto ArgString = A->getAsString(Args);
std::string Nearest;
if (getOpts().findNearest(ArgString, Nearest, VisibilityMask) > 1) {
- if (!IsCLMode() &&
+ if (IsFlangMode()) {
+ if (getOpts().findExact(ArgString, Nearest,
+ llvm::opt::Visibility(options::FC1Option))) {
+ DiagID = diag::err_drv_unknown_argument_with_suggestion;
+ Diags.Report(DiagID) << ArgString << "-Xflang " + Nearest;
+ } else {
+ DiagID = diag::err_drv_unknown_argument;
+ Diags.Report(DiagID) << ArgString;
+ }
+ } else if (!IsCLMode() &&
getOpts().findExact(ArgString, Nearest,
llvm::opt::Visibility(options::CC1Option))) {
DiagID = diag::err_drv_unknown_argument_with_suggestion;
diff --git a/flang/test/Driver/flang-f-opts.f90 b/flang/test/Driver/flang-f-opts.f90
index b972b9b7b2a59..6720c4e534fdb 100644
--- a/flang/test/Driver/flang-f-opts.f90
+++ b/flang/test/Driver/flang-f-opts.f90
@@ -1,5 +1,5 @@
-! Test for warnings generated when parsing driver options. You can use this file for relatively small tests and to avoid creating
-! new test files.
+! Test for errors and warnings generated when parsing driver options. You can
+! use this file for relatively small tests and to avoid creating new test files.
! RUN: %flang -### -S -O4 -ffp-contract=on %s 2>&1 | FileCheck %s
@@ -13,3 +13,20 @@
! CHECK-PROFILE-GENERATE-LLVM: "-fprofile-generate"
! RUN: %flang -### -S -fprofile-use=%S %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-DIR %s
! CHECK-PROFILE-USE-DIR: "-fprofile-use={{.*}}"
+
+! When issuing a warning with a suggestion, ensure that the suggestion uses
+! "-Xflang" in the diagnostic message. This is typically issued when an option
+! that is available for `flang -fc1` is passed to `flang`. We use -complex-range
+! since it is only available for fc1. If this option is ever exposed to `flang`,
+! a different option will have to be used in the test below.
+!
+! RUN: not %flang -complex-range=full %s 2>&1 \
+! RUN: | FileCheck %s -check-prefix UNKNOWN-SUGGEST
+!
+! UNKNOWN-SUGGEST: error: unknown argument '-complex-range=full';
+! UNKNOWN-SUGGEST-SAME: did you mean '-Xflang -complex-range=full'
+!
+! RUN: not %flang -not-an-option %s 2>&1 \
+! RUN: | FileCheck %s -check-prefix UNKNOWN-NO-SUGGEST
+!
+! UNKNOWN-NO-SUGGEST: error: unknown argument: '-not-an-option'{{$}}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Tarun
bcf78f6 to
abc5c77
Compare
When an option that is only available in `flang -fc1` is provided to `flang`, emit a diagnostic with a suggestion containing "did you mean -Xflang '-foo'". Partially addresses llvm#163550.
abc5c77 to
e7d7243
Compare
When an option that is only available in
flang -fc1is provided toflang, emit a diagnostic with a suggestion containing "did you mean -Xflang '-foo'".Partially addresses #163550.