Skip to content

Commit f84c4c4

Browse files
authored
[flang][Driver] Better error message when multiple actions are specified (#165575)
If multiple action options are specified on the command line, list them all in the error message that is emitted Fixes #79458
1 parent 3c31cde commit f84c4c4

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ def warn_drv_yc_multiple_inputs_clang_cl : Warning<
312312
def warn_drv_potentially_misspelled_joined_argument : Warning<
313313
"joined argument treated as '%0'; did you mean '%1'?">, InGroup<UnknownArgument>;
314314

315+
def err_drv_too_many_actions: Error<
316+
"only one action option is allowed. Got %0">;
315317
def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
316318
def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
317319
def err_drv_invalid_value_with_suggestion : Error<

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,15 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
595595
// -cc1` does accept multiple action options, but will only consider the
596596
// rightmost one.
597597
if (args.hasMultipleArgs(clang::driver::options::OPT_Action_Group)) {
598-
const unsigned diagID = diags.getCustomDiagID(
599-
clang::DiagnosticsEngine::Error, "Only one action option is allowed");
600-
diags.Report(diagID);
598+
llvm::SmallString<32> buf;
599+
llvm::raw_svector_ostream os(buf);
600+
for (const llvm::opt::Arg *arg :
601+
args.filtered(clang::driver::options::OPT_Action_Group)) {
602+
if (buf.size())
603+
os << ", ";
604+
os << "'" << arg->getSpelling() << "'";
605+
}
606+
diags.Report(clang::diag::err_drv_too_many_actions) << buf;
601607
return false;
602608
}
603609

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
! Verify that the frontend driver error-out if multiple actions are specified
2-
3-
! RUN: not %flang_fc1 -E -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=ERROR
4-
! RUN: not %flang_fc1 -fsyntax-only -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=ERROR
5-
6-
! ERROR: error: Only one action option is allowed
7-
8-
end progream
1+
! Verify that the frontend driver raises the expected error when multiple
2+
! actions are specified.
3+
!
4+
! RUN: not %flang_fc1 -fsyntax-only -fsyntax-only %s 2>&1 \
5+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-1
6+
!
7+
! RUN: not %flang_fc1 -E -fsyntax-only %s 2>&1 \
8+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-2
9+
!
10+
! RUN: not %flang_fc1 -fsyntax-only -E -emit-llvm %s 2>&1 \
11+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-3
12+
!
13+
! If one or more options are specified with -Xflang, they will appear last in
14+
! the error message.
15+
!
16+
! RUN: not %flang -S -Xflang -emit-llvm %s 2>&1 \
17+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-4
18+
!
19+
! RUN: not %flang -Xflang -emit-llvm -S %s 2>&1 \
20+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-4
21+
!
22+
! RUN: not %flang -Xflang -emit-obj -S -Xflang -emit-llvm %s 2>&1 \
23+
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-5
24+
!
25+
! ERROR: error: only one action option is allowed.
26+
! ACTIONS-1: Got '-fsyntax-only', '-fsyntax-only'
27+
! ACTIONS-2: Got '-E', '-fsyntax-only'
28+
! ACTIONS-3: Got '-fsyntax-only', '-E', '-emit-llvm'
29+
! ACTIONS-4: Got '-S', '-emit-llvm'
30+
! ACTIONS-5: Got '-S', '-emit-obj', '-emit-llvm'

0 commit comments

Comments
 (0)