[flang-commits] [flang] 2b4c9bc - [flang][driver] Add checks for missing option arguments

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Fri Jun 4 07:17:28 PDT 2021


Author: Andrzej Warzynski
Date: 2021-06-04T15:16:56+01:00
New Revision: 2b4c9bc4d489a4be1c5aa1924fba542dc80ab0c9

URL: https://github.com/llvm/llvm-project/commit/2b4c9bc4d489a4be1c5aa1924fba542dc80ab0c9
DIFF: https://github.com/llvm/llvm-project/commit/2b4c9bc4d489a4be1c5aa1924fba542dc80ab0c9.diff

LOG: [flang][driver] Add checks for missing option arguments

With this patch, the following invocation of the frontend driver will
return an error:
```
flang-new -fc1 input-file.f90 -o
```
Similar logic applies to other options that require arguments.

Similar checks are already available in the compiler driver, flang-new
(that's implemented in clangDriver).

Differential Revision: https://reviews.llvm.org/D103554

Added: 
    flang/test/Driver/missing-arg.f90

Modified: 
    flang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 1d18dda5e7eea..6d9a3a7f31947 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -501,6 +501,13 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
   llvm::opt::InputArgList args = opts.ParseArgs(
       commandLineArgs, missingArgIndex, missingArgCount, includedFlagsBitmask);
 
+  // Check for missing argument error.
+  if (missingArgCount) {
+    diags.Report(clang::diag::err_drv_missing_argument)
+        << args.getArgString(missingArgIndex) << missingArgCount;
+    success = false;
+  }
+
   // Issue errors on unknown arguments
   for (const auto *a : args.filtered(clang::driver::options::OPT_UNKNOWN)) {
     auto argString = a->getAsString(args);

diff  --git a/flang/test/Driver/missing-arg.f90 b/flang/test/Driver/missing-arg.f90
new file mode 100644
index 0000000000000..3a16542e04e83
--- /dev/null
+++ b/flang/test/Driver/missing-arg.f90
@@ -0,0 +1,21 @@
+! Make sure that frontend driver options that require arguments are
+! correctly rejected when the argument value is missing.
+
+! REQUIRES: new-flang-driver
+
+!-----------
+! RUN lines
+!-----------
+! RUN: not %flang_fc1 -E %s -o 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -U 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -D 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -I 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -J 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -module-dir 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -module-suffix 2>&1 | FileCheck %s
+! RUN: not %flang_fc1 -E %s -fintrinsic-modules-path 2>&1 | FileCheck %s
+
+!-----------------------
+! EXPECTED OUTPUT
+!-----------------------
+! CHECK: error: argument to '-{{.*}}' is missing (expected 1 value)


        


More information about the flang-commits mailing list