https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/164741
>From 76d77907277cec58ac7bb7056164513f4d73837b Mon Sep 17 00:00:00 2001 From: Tarun Prabhu <[email protected]> Date: Wed, 22 Oct 2025 19:29:35 -0600 Subject: [PATCH 1/3] [flang][driver] Use -Xflang in diagnostics 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 #163550. --- clang/lib/Driver/Driver.cpp | 11 ++++++++++- flang/test/Driver/flang-f-opts.f90 | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) 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'{{$}} >From 33cb55bac5d880e4d786aa71c9a06e49f4068b33 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu <[email protected]> Date: Wed, 22 Oct 2025 19:37:33 -0600 Subject: [PATCH 2/3] Improve clarity of comment --- flang/test/Driver/flang-f-opts.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flang/test/Driver/flang-f-opts.f90 b/flang/test/Driver/flang-f-opts.f90 index 6720c4e534fdb..7f68bd73636ac 100644 --- a/flang/test/Driver/flang-f-opts.f90 +++ b/flang/test/Driver/flang-f-opts.f90 @@ -14,8 +14,8 @@ ! 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 +! When emitting an error with a suggestion, ensure that the diagnostic message +! uses '-Xflang' instead of '-Xclang'. This is typically emitted 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. >From 142cc0f2a5ae122a9e4f41c404d48cab5177fcc3 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu <[email protected]> Date: Wed, 22 Oct 2025 19:38:48 -0600 Subject: [PATCH 3/3] Fix clang-format error --- clang/lib/Driver/Driver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index afaf6c2691ac6..71c52807091ba 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -317,9 +317,9 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings, DiagID = diag::err_drv_unknown_argument; Diags.Report(DiagID) << ArgString; } - } else if (!IsCLMode() && - getOpts().findExact(ArgString, Nearest, - llvm::opt::Visibility(options::CC1Option))) { + } else if (!IsCLMode() && getOpts().findExact(ArgString, Nearest, + llvm::opt::Visibility( + options::CC1Option))) { DiagID = diag::err_drv_unknown_argument_with_suggestion; Diags.Report(DiagID) << ArgString << "-Xclang " + Nearest; } else { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
