From 68d7f06092e56b17eb0cddf560a9d9fe8afb7dd8 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Wed, 22 Jan 2020 16:53:38 -0500 Subject: [PATCH] Clang] Fix expansion of response files in -Wp after integrated-cc1 change After rGb4a99a061f517e60985667e39519f60186cbb469, passing a response file such as -Wp,@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 --- clang/include/clang/Driver/Driver.h | 2 +- clang/test/Driver/Wp-args.c | 10 ++++++++++ clang/tools/driver/driver.cpp | 22 +++++++++++++--------- 3 files changed, 24 insertions(+), 10 deletions(-) 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 @@ public: /// 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 argv); + typedef int (*CC1ToolFunc)(SmallVectorImpl &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 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 &argv, TheDriver.setInstalledDir(InstalledPathParent); } -static int ExecuteCC1Tool(ArrayRef argv) { +static int ExecuteCC1Tool(SmallVectorImpl &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"; -- 2.11.4.GIT