Skip to content

Commit 68d7f06

Browse files
committed
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
1 parent ed80c86 commit 68d7f06

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Driver {
208208
/// When the clangDriver lib is used through clang.exe, this provides a
209209
/// shortcut for executing the -cc1 command-line directly, in the same
210210
/// process.
211-
typedef int (*CC1ToolFunc)(ArrayRef<const char *> argv);
211+
typedef int (*CC1ToolFunc)(SmallVectorImpl<const char *> &ArgV);
212212
CC1ToolFunc CC1Main = nullptr;
213213

214214
private:

clang/test/Driver/Wp-args.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@
1919
// MMD: "-cc1"
2020
// MMD-NOT: -MMD
2121
// MMD: "-dependency-file" "Wp-args.d"
22+
23+
// Ensure response files are properly expanded with -Wp
24+
// RUN: echo -DTEST > %t.rsp
25+
// RUN: %clang -Wp,@%t.rsp -E %s | FileCheck -check-prefix RSP %s
26+
27+
#ifdef TEST
28+
void foo();
29+
#endif
30+
31+
// RSP: foo()

clang/tools/driver/driver.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
241241
*NumberSignPtr = '=';
242242
}
243243

244-
static int ExecuteCC1Tool(ArrayRef<const char *> argv);
245-
246244
static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
247245
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
248246
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
@@ -313,21 +311,27 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv,
313311
TheDriver.setInstalledDir(InstalledPathParent);
314312
}
315313

316-
static int ExecuteCC1Tool(ArrayRef<const char *> argv) {
314+
static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
317315
// If we call the cc1 tool from the clangDriver library (through
318316
// Driver::CC1Main), we need to clean up the options usage count. The options
319317
// are currently global, and they might have been used previously by the
320318
// driver.
321319
llvm::cl::ResetAllOptionOccurrences();
322-
StringRef Tool = argv[1];
323-
void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
320+
321+
llvm::BumpPtrAllocator A;
322+
llvm::StringSaver Saver(A);
323+
llvm::cl::ExpandResponseFiles(Saver, &llvm::cl::TokenizeGNUCommandLine, ArgV,
324+
/*MarkEOLs=*/false);
325+
StringRef Tool = ArgV[1];
326+
void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
324327
if (Tool == "-cc1")
325-
return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
328+
return cc1_main(makeArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
326329
if (Tool == "-cc1as")
327-
return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
330+
return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
331+
GetExecutablePathVP);
328332
if (Tool == "-cc1gen-reproducer")
329-
return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
330-
333+
return cc1gen_reproducer_main(makeArrayRef(ArgV).slice(2), ArgV[0],
334+
GetExecutablePathVP);
331335
// Reject unknown tools.
332336
llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
333337
<< "Valid tools include '-cc1' and '-cc1as'.\n";

0 commit comments

Comments
 (0)