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 &); CC1ToolFunc CC1Main = nullptr; private: Index: clang/lib/Driver/Job.cpp =================================================================== --- clang/lib/Driver/Job.cpp +++ clang/lib/Driver/Job.cpp @@ -384,7 +384,6 @@ SmallVector Argv; Argv.push_back(getExecutable()); Argv.append(getArguments().begin(), getArguments().end()); - Argv.push_back(nullptr); // This flag simply indicates that the program couldn't start, which isn't // applicable here. 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"); @@ -318,7 +316,6 @@ // 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; if (Tool == "-cc1") @@ -334,17 +331,13 @@ return 1; } -int main(int argc_, const char **argv_) { - noteBottomOfStack(); - llvm::InitLLVM X(argc_, argv_); - SmallVector argv(argv_, argv_ + argc_); - - if (llvm::sys::Process::FixupStandardFileDescriptors()) - return 1; - - llvm::InitializeAllTargets(); +int ExecuteClangTool(SmallVectorImpl &argv) { auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(argv[0]); + static unsigned ReenteranceCount; + if (ReenteranceCount++) + llvm::cl::ResetAllOptionOccurrences(); + llvm::BumpPtrAllocator A; llvm::StringSaver Saver(A); @@ -480,7 +473,7 @@ SetBackdoorDriverOutputsFromEnvVars(TheDriver); if (!UseNewCC1Process) { - TheDriver.CC1Main = &ExecuteCC1Tool; + TheDriver.CC1Main = &ExecuteClangTool; // Ensure the CC1Command actually catches cc1 crashes llvm::CrashRecoveryContext::Enable(); } @@ -543,3 +536,15 @@ // failing command. return Res; } + +int main(int argc_, const char **argv_) { + noteBottomOfStack(); + llvm::InitLLVM X(argc_, argv_); + SmallVector argv(argv_, argv_ + argc_); + + if (llvm::sys::Process::FixupStandardFileDescriptors()) + return 1; + + llvm::InitializeAllTargets(); + return ExecuteClangTool(argv); +}