From d26520f6f78785b0c4c296a8a992f2adb656c6ec Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Tue, 21 Dec 2021 17:41:26 -0500 Subject: [PATCH] [Clang] Own the CommandLineArgs in CodeGenOptions Fixes PR52704 : https://github.com/llvm/llvm-project/issues/52704 Differential Revision: https://reviews.llvm.org/D116011 --- clang/include/clang/Basic/CodeGenOptions.h | 2 +- clang/lib/Driver/Job.cpp | 2 ++ clang/lib/Frontend/CompilerInvocation.cpp | 2 +- llvm/include/llvm/MC/MCTargetOptions.h | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index d4781b647b87..33ec03a17136 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -398,7 +398,7 @@ public: /// Executable and command-line used to create a given CompilerInvocation. /// Most of the time this will be the full -cc1 command. const char *Argv0 = nullptr; - ArrayRef CommandLineArgs; + std::vector CommandLineArgs; /// The minimum hotness value a diagnostic needs in order to be included in /// optimization diagnostics. diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp index 5b87106b6565..f63763effaff 100644 --- a/clang/lib/Driver/Job.cpp +++ b/clang/lib/Driver/Job.cpp @@ -388,6 +388,8 @@ int CC1Command::Execute(ArrayRef> Redirects, Argv.push_back(getExecutable()); Argv.append(getArguments().begin(), getArguments().end()); Argv.push_back(nullptr); + Argv.pop_back(); // The terminating null element shall not be part of the + // slice (main() behavior). // This flag simply indicates that the program couldn't start, which isn't // applicable here. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 106da642f361..b71addd84bfd 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4518,7 +4518,7 @@ bool CompilerInvocation::CreateFromArgsImpl( // Store the command-line for using in the CodeView backend. Res.getCodeGenOpts().Argv0 = Argv0; - Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs; + append_range(Res.getCodeGenOpts().CommandLineArgs, CommandLineArgs); FixupInvocation(Res, Diags, Args, DashX); diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h index b006bb321819..3510eeca8953 100644 --- a/llvm/include/llvm/MC/MCTargetOptions.h +++ b/llvm/include/llvm/MC/MCTargetOptions.h @@ -65,7 +65,7 @@ public: std::string COFFOutputFilename; const char *Argv0 = nullptr; - ArrayRef CommandLineArgs; + ArrayRef CommandLineArgs; /// Additional paths to search for `.include` directives when using the /// integrated assembler. -- 2.11.4.GIT