[PATCH] D103554: [flang][driver] Add checks for missing option arguments

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b4c9bc4d489: [flang][driver] Add checks for missing option arguments (authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D103554?vs=349369&id=349865#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103554/new/

https://reviews.llvm.org/D103554

Files:
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/missing-arg.f90


Index: flang/test/Driver/missing-arg.f90
===================================================================
--- /dev/null
+++ 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)
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -501,6 +501,13 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103554.349865.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/2a31a642/attachment.bin>


More information about the llvm-commits mailing list