|
50 | 50 | #include "llvm/Support/CommandLine.h"
|
51 | 51 | #include "llvm/Support/MemoryBuffer.h"
|
52 | 52 | #include "llvm/Support/PrettyStackTrace.h"
|
| 53 | +#include "llvm/Support/Program.h" |
53 | 54 | #include "llvm/Support/TimeProfiler.h"
|
54 | 55 | #include "llvm/Support/Timer.h"
|
55 | 56 | #include "llvm/Support/ToolOutputFile.h"
|
@@ -321,6 +322,40 @@ static bool actionRequiresCodeGen(BackendAction Action) {
|
321 | 322 | Action != Backend_EmitLL;
|
322 | 323 | }
|
323 | 324 |
|
| 325 | +static std::string flattenClangCommandLine(ArrayRef<std::string> Args, |
| 326 | + StringRef MainFilename) { |
| 327 | + if (Args.empty()) |
| 328 | + return std::string{}; |
| 329 | + |
| 330 | + std::string FlatCmdLine; |
| 331 | + raw_string_ostream OS(FlatCmdLine); |
| 332 | + bool PrintedOneArg = false; |
| 333 | + if (!StringRef(Args[0]).contains("-cc1")) { |
| 334 | + llvm::sys::printArg(OS, "-cc1", /*Quote=*/true); |
| 335 | + PrintedOneArg = true; |
| 336 | + } |
| 337 | + for (unsigned i = 0; i < Args.size(); i++) { |
| 338 | + StringRef Arg = Args[i]; |
| 339 | + if (Arg.empty()) |
| 340 | + continue; |
| 341 | + if (Arg == "-main-file-name" || Arg == "-o") { |
| 342 | + i++; // Skip this argument and next one. |
| 343 | + continue; |
| 344 | + } |
| 345 | + if (Arg.starts_with("-object-file-name") || Arg == MainFilename) |
| 346 | + continue; |
| 347 | + // Skip fmessage-length for reproducibility. |
| 348 | + if (Arg.starts_with("-fmessage-length")) |
| 349 | + continue; |
| 350 | + if (PrintedOneArg) |
| 351 | + OS << " "; |
| 352 | + llvm::sys::printArg(OS, Arg, /*Quote=*/true); |
| 353 | + PrintedOneArg = true; |
| 354 | + } |
| 355 | + OS.flush(); |
| 356 | + return FlatCmdLine; |
| 357 | +} |
| 358 | + |
324 | 359 | static bool initTargetOptions(DiagnosticsEngine &Diags,
|
325 | 360 | llvm::TargetOptions &Options,
|
326 | 361 | const CodeGenOptions &CodeGenOpts,
|
@@ -483,8 +518,9 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
|
483 | 518 | Entry.Group == frontend::IncludeDirGroup::System))
|
484 | 519 | Options.MCOptions.IASSearchPaths.push_back(
|
485 | 520 | Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
|
486 |
| - Options.MCOptions.Argv0 = CodeGenOpts.Argv0; |
487 |
| - Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs; |
| 521 | + Options.MCOptions.Argv0 = CodeGenOpts.Argv0 ? CodeGenOpts.Argv0 : ""; |
| 522 | + Options.MCOptions.CommandlineArgs = flattenClangCommandLine( |
| 523 | + CodeGenOpts.CommandLineArgs, CodeGenOpts.MainFileName); |
488 | 524 | Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
|
489 | 525 | Options.MCOptions.PPCUseFullRegisterNames =
|
490 | 526 | CodeGenOpts.PPCUseFullRegisterNames;
|
|
0 commit comments