[llvm-branch-commits] [clang] 85ee70e - Clang] Fix expansion of response files in -Wp after integrated-cc1 change

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 23 09:20:01 PST 2020


Author: Alexandre Ganea
Date: 2020-01-23T18:17:22+01:00
New Revision: 85ee70e86456e3bcb3c706c404db497c5a448602

URL: https://github.com/llvm/llvm-project/commit/85ee70e86456e3bcb3c706c404db497c5a448602
DIFF: https://github.com/llvm/llvm-project/commit/85ee70e86456e3bcb3c706c404db497c5a448602.diff

LOG: Clang] Fix expansion of response files in -Wp after integrated-cc1 change

After rGb4a99a061f517e60985667e39519f60186cbb469, passing a response file such as -Wp, at a.rsp wasn't working anymore because .rsp expansion happens inside clang's main() function.

This patch adds response file expansion in the -cc1 tool.

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

(cherry picked from commit 68d7f06092e56b17eb0cddf560a9d9fe8afb7dd8)

Added: 
    

Modified: 
    clang/include/clang/Driver/Driver.h
    clang/test/Driver/Wp-args.c
    clang/tools/driver/driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h
index fd25663bd358..6c3feaba0568 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -208,7 +208,7 @@ class Driver {
   /// When the clangDriver lib is used through clang.exe, this provides a
   /// shortcut for executing the -cc1 command-line directly, in the same
   /// process.
-  typedef int (*CC1ToolFunc)(ArrayRef<const char *> argv);
+  typedef int (*CC1ToolFunc)(SmallVectorImpl<const char *> &ArgV);
   CC1ToolFunc CC1Main = nullptr;
 
 private:

diff  --git a/clang/test/Driver/Wp-args.c b/clang/test/Driver/Wp-args.c
index e01e2a2651f0..587b7b83e4ca 100644
--- a/clang/test/Driver/Wp-args.c
+++ b/clang/test/Driver/Wp-args.c
@@ -19,3 +19,13 @@
 // MMD: "-cc1"
 // MMD-NOT: -MMD
 // MMD: "-dependency-file" "Wp-args.d"
+
+// Ensure response files are properly expanded with -Wp
+// RUN: echo -DTEST > %t.rsp
+// RUN: %clang -Wp,@%t.rsp -E %s | FileCheck -check-prefix RSP %s
+
+#ifdef TEST
+void foo();
+#endif
+
+// RSP: foo()

diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 39f6c7f62be4..4457e40ff04b 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -241,8 +241,6 @@ static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
       *NumberSignPtr = '=';
 }
 
-static int ExecuteCC1Tool(ArrayRef<const char *> argv);
-
 static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
   // Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
   TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
@@ -313,21 +311,27 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv,
     TheDriver.setInstalledDir(InstalledPathParent);
 }
 
-static int ExecuteCC1Tool(ArrayRef<const char *> argv) {
+static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
   // If we call the cc1 tool from the clangDriver library (through
   // Driver::CC1Main), we need to clean up the options usage count. The options
   // are currently global, and they might have been used previously by the
   // driver.
   llvm::cl::ResetAllOptionOccurrences();
-  StringRef Tool = argv[1];
-  void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
+
+  llvm::BumpPtrAllocator A;
+  llvm::StringSaver Saver(A);
+  llvm::cl::ExpandResponseFiles(Saver, &llvm::cl::TokenizeGNUCommandLine, ArgV,
+                                /*MarkEOLs=*/false);
+  StringRef Tool = ArgV[1];
+  void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
   if (Tool == "-cc1")
-    return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
+    return cc1_main(makeArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
   if (Tool == "-cc1as")
-    return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
+    return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
+                      GetExecutablePathVP);
   if (Tool == "-cc1gen-reproducer")
-    return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
-
+    return cc1gen_reproducer_main(makeArrayRef(ArgV).slice(2), ArgV[0],
+                                  GetExecutablePathVP);
   // Reject unknown tools.
   llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
                << "Valid tools include '-cc1' and '-cc1as'.\n";


        


More information about the llvm-branch-commits mailing list