[flang-commits] [PATCH] D124846: [flang][driver] Support reading response files

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue May 3 05:20:34 PDT 2022


rovka created this revision.
rovka added reviewers: awarzynski, kiranchandramohan, sscalpone, pmccormick.
rovka added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
rovka requested review of this revision.

Add support for reading response files in the flang driver. Response
files contain command line arguments and are used whenever a command
becomes longer than the shell/environment limit.

This patch hardcodes GNU tokenization, since we don't have a CL mode for
the driver. In the future we might want to add a --rsp-quoting command
line option, like clang has, to accommodate Windows platforms.

Note that this patch is not very useful on its own - if the compiler has
to be invoked with a response file, then there's a high probability that
the follow-up fc1 or link commands will also be too long. The support
for writing our own response files in such a case will be the subject of
a future patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124846

Files:
  flang/test/Driver/response-file.f90
  flang/tools/flang-driver/driver.cpp


Index: flang/tools/flang-driver/driver.cpp
===================================================================
--- flang/tools/flang-driver/driver.cpp
+++ flang/tools/flang-driver/driver.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -75,6 +76,13 @@
   clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang");
   std::string driverPath = GetExecutablePath(args[0]);
 
+  // Parse response files. We're defaulting to the GNU syntax, since we don't
+  // have a CL mode.
+  llvm::BumpPtrAllocator a;
+  llvm::StringSaver saver(a);
+  llvm::cl::TokenizerCallback tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+  llvm::cl::ExpandResponseFiles(saver, tokenizer, args, /* MarkEOLs=*/false);
+
   // Check if flang-new is in the frontend mode
   auto firstArg = std::find_if(
       args.begin() + 1, args.end(), [](const char *a) { return a != nullptr; });
Index: flang/test/Driver/response-file.f90
===================================================================
--- /dev/null
+++ flang/test/Driver/response-file.f90
@@ -0,0 +1,15 @@
+! Test that the driver can process response files.
+
+! RUN: echo "-DTEST" > %basename_t.rsp
+! RUN: %flang -E -cpp @%basename_t.rsp %s -o - | FileCheck %s
+! RUN: %flang_fc1 -E -cpp @%basename_t.rsp %s -o - | FileCheck %s
+
+! CHECK-LABEL: program test
+! CHECK: end program
+
+#ifdef TEST
+program test
+end program
+#else
+We should have read the define from the response file.
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124846.426655.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220503/08e54052/attachment.bin>


More information about the flang-commits mailing list