Skip to content

Commit ad9098f

Browse files
committed
[master-next] Fix up the driver's use of PROGRAM_START after PR #16362
On the master-next branch, the InitLLVM class used by the PROGRAM_START macro can modify the argc/argv values (currently only on Windows). Expanding response files before initializing the stack trace also modifies the arguments so use a separate SmallVector for each copy of the argument vector.
1 parent 42ca684 commit ad9098f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/driver/driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int run_driver(StringRef ExecName,
180180
}
181181

182182
int main(int argc_, const char **argv_) {
183-
SmallVector<const char *, 256> argv(&argv_[0], &argv_[argc_]);
183+
SmallVector<const char *, 256> args(&argv_[0], &argv_[argc_]);
184184

185185
// Expand any response files in the command line argument vector - arguments
186186
// may be passed through response files in the event of command line length
@@ -192,11 +192,15 @@ int main(int argc_, const char **argv_) {
192192
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows() ?
193193
llvm::cl::TokenizeWindowsCommandLine :
194194
llvm::cl::TokenizeGNUCommandLine,
195-
argv);
195+
args);
196196

197197
// Initialize the stack trace using the parsed argument vector with expanded
198198
// response files.
199-
PROGRAM_START(argv.size(), argv.data());
199+
int ExpandedArgc = args.size();
200+
const char **ExpandedArgv = args.data();
201+
PROGRAM_START(ExpandedArgc, ExpandedArgv);
202+
SmallVector<const char *, 256> argv(&ExpandedArgv[0],
203+
&ExpandedArgv[ExpandedArgc]);
200204

201205
// Check if this invocation should execute a subcommand.
202206
StringRef ExecName = llvm::sys::path::stem(argv[0]);

0 commit comments

Comments
 (0)