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

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed May 18 01:26:19 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c0b03f6e706: [flang][driver] Support parsing response files (authored by rovka).

Changed prior to commit:
  https://reviews.llvm.org/D124846?vs=427570&id=430270#toc

Repository:
  rG LLVM Github Monorepo

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

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
@@ -25,6 +25,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"
@@ -71,6 +72,13 @@
   return 1;
 }
 
+static void ExpandResponseFiles(
+    llvm::StringSaver &saver, llvm::SmallVectorImpl<const char *> &args) {
+  // We're defaulting to the GNU syntax, since we don't have a CL mode.
+  llvm::cl::TokenizerCallback tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+  llvm::cl::ExpandResponseFiles(saver, tokenizer, args, /* MarkEOLs=*/false);
+}
+
 int main(int argc, const char **argv) {
 
   // Initialize variables to call the driver
@@ -80,6 +88,10 @@
   clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang");
   std::string driverPath = getExecutablePath(args[0]);
 
+  llvm::BumpPtrAllocator a;
+  llvm::StringSaver saver(a);
+  ExpandResponseFiles(saver, args);
+
   // 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,17 @@
+! 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
+! RUN: not %flang %basename_t.rsp %s -o /dev/null
+! RUN: not %flang_fc1 %basenamt_t.rsp %s -o /dev/null
+
+! 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.430270.patch
Type: text/x-patch
Size: 2039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220518/b14c1867/attachment.bin>


More information about the flang-commits mailing list