[PATCH] D111781: [flang] Make the frontend driver error out when requesting multiple actions
Andrzej Warzynski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 14 01:13:49 PDT 2021
awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
With this change, the following invocations are treated as errors
(multiple actions are specified):
$ flang-new -fc1 -E -fsyntax-only file.95
$ flang-new -fc1 -fsyntax-only -fsyntax-only file.95
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111781
Files:
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/multiple-actions-error.f95
llvm/include/llvm/Option/ArgList.h
Index: llvm/include/llvm/Option/ArgList.h
===================================================================
--- llvm/include/llvm/Option/ArgList.h
+++ llvm/include/llvm/Option/ArgList.h
@@ -245,6 +245,12 @@
return getLastArg(Ids...) != nullptr;
}
+ /// Return true if the arg list contains multiple arguments matching \p Id.
+ bool hasMultipleArgs(OptSpecifier Id) const {
+ auto Args = filtered(Id);
+ return (++Args.begin()) != Args.end();
+ }
+
/// Return the last argument matching \p Id, or null.
template<typename ...OptSpecifiers>
Arg *getLastArg(OptSpecifiers ...Ids) const {
Index: flang/test/Driver/multiple-actions-error.f95
===================================================================
--- /dev/null
+++ flang/test/Driver/multiple-actions-error.f95
@@ -0,0 +1,8 @@
+! 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
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -107,6 +107,14 @@
// By default the frontend driver creates a ParseSyntaxOnly action.
opts.programAction = ParseSyntaxOnly;
+ // Treat multiple action options as an invocation error.
+ 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);
+ return false;
+ }
+
// Identify the action (i.e. opts.ProgramAction)
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_Action_Group)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111781.379621.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211014/1e82dd9f/attachment.bin>
More information about the llvm-commits
mailing list