Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def warn_drv_yc_multiple_inputs_clang_cl : Warning<
def warn_drv_potentially_misspelled_joined_argument : Warning<
"joined argument treated as '%0'; did you mean '%1'?">, InGroup<UnknownArgument>;

def err_drv_too_many_actions: Error<
"only one action option is allowed. Got %0">;
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<
Expand Down
12 changes: 9 additions & 3 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,15 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
// -cc1` does accept multiple action options, but will only consider the
// rightmost one.
if (args.hasMultipleArgs(clang::driver::options::OPT_Action_Group)) {
const unsigned diagID = diags.getCustomDiagID(
clang::DiagnosticsEngine::Error, "Only one action option is allowed");
diags.Report(diagID);
llvm::SmallString<32> buf;
llvm::raw_svector_ostream os(buf);
for (const llvm::opt::Arg *arg :
args.filtered(clang::driver::options::OPT_Action_Group)) {
if (buf.size())
os << ", ";
os << "'" << arg->getSpelling() << "'";
}
diags.Report(clang::diag::err_drv_too_many_actions) << buf;
return false;
}

Expand Down
38 changes: 30 additions & 8 deletions flang/test/Driver/multiple-actions-error.f95
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
! Verify that the frontend driver error-out if multiple actions are specified

! RUN: not %flang_fc1 -E -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=ERROR
! RUN: not %flang_fc1 -fsyntax-only -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=ERROR

! ERROR: error: Only one action option is allowed

end progream
! Verify that the frontend driver raises the expected error when multiple
! actions are specified.
!
! RUN: not %flang_fc1 -fsyntax-only -fsyntax-only %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-1
!
! RUN: not %flang_fc1 -E -fsyntax-only %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-2
!
! RUN: not %flang_fc1 -fsyntax-only -E -emit-llvm %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-3
!
! If one or more options are specified with -Xflang, they will appear last in
! the error message.
!
! RUN: not %flang -S -Xflang -emit-llvm %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-4
!
! RUN: not %flang -Xflang -emit-llvm -S %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-4
!
! RUN: not %flang -Xflang -emit-obj -S -Xflang -emit-llvm %s 2>&1 \
! RUN: | FileCheck %s --check-prefixes=ERROR,ACTIONS-5
!
! ERROR: error: only one action option is allowed.
! ACTIONS-1: Got '-fsyntax-only', '-fsyntax-only'
! ACTIONS-2: Got '-E', '-fsyntax-only'
! ACTIONS-3: Got '-fsyntax-only', '-E', '-emit-llvm'
! ACTIONS-4: Got '-S', '-emit-llvm'
! ACTIONS-5: Got '-S', '-emit-obj', '-emit-llvm'