Index: clang/include/clang/Driver/Driver.h =================================================================== --- clang/include/clang/Driver/Driver.h +++ clang/include/clang/Driver/Driver.h @@ -208,7 +208,7 @@ /// 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: Index: clang/test/Driver/Wp-args.c =================================================================== --- clang/test/Driver/Wp-args.c +++ clang/test/Driver/Wp-args.c @@ -19,3 +19,9 @@ // MMD: "-cc1" // MMD-NOT: -MMD // MMD: "-dependency-file" "Wp-args.d" + +// Ensure response files are properly expanded with -Wp +// RUN: echo -rewrite-macros > %t.rsp +// RUN: %clang -Wp,@%t.rsp -E %s | FileCheck -check-prefix RSP %s + +// RSP: inception Index: clang/tools/driver/driver.cpp =================================================================== --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -241,8 +241,6 @@ *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 @@ 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";