[llvm] d26520f - [Clang] Own the CommandLineArgs in CodeGenOptions

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 21 14:41:45 PST 2021


Author: Alexandre Ganea
Date: 2021-12-21T17:41:35-05:00
New Revision: d26520f6f78785b0c4c296a8a992f2adb656c6ec

URL: https://github.com/llvm/llvm-project/commit/d26520f6f78785b0c4c296a8a992f2adb656c6ec
DIFF: https://github.com/llvm/llvm-project/commit/d26520f6f78785b0c4c296a8a992f2adb656c6ec.diff

LOG: [Clang] Own the CommandLineArgs in CodeGenOptions

Fixes PR52704 : https://github.com/llvm/llvm-project/issues/52704

Differential Revision: https://reviews.llvm.org/D116011

Added: 
    

Modified: 
    clang/include/clang/Basic/CodeGenOptions.h
    clang/lib/Driver/Job.cpp
    clang/lib/Frontend/CompilerInvocation.cpp
    llvm/include/llvm/MC/MCTargetOptions.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index d4781b647b877..33ec03a171362 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -398,7 +398,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// 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<const char *> CommandLineArgs;
+  std::vector<std::string> 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 5b87106b6565d..f63763effaffe 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -388,6 +388,8 @@ int CC1Command::Execute(ArrayRef<llvm::Optional<StringRef>> 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 106da642f3619..b71addd84bfd9 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 b006bb321819b..3510eeca89538 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -65,7 +65,7 @@ class MCTargetOptions {
   std::string COFFOutputFilename;
 
   const char *Argv0 = nullptr;
-  ArrayRef<const char *> CommandLineArgs;
+  ArrayRef<std::string> CommandLineArgs;
 
   /// Additional paths to search for `.include` directives when using the
   /// integrated assembler.


        


More information about the llvm-commits mailing list