[clang] b76c7c6 - [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 27 00:19:05 PDT 2021


Author: Jan Svoboda
Date: 2021-07-27T09:18:58+02:00
New Revision: b76c7c6faf06bb02b7b7b6bba3f6eb8a33edcdca

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

LOG: [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

This patch exposes `InputInfo` in `Job` instead of plain filenames. This is useful in a follow-up patch that uses this to recognize `-cc1` commands interesting for Clang tooling.

Depends on D106787.

Reviewed By: dexonsmith

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

Added: 
    

Modified: 
    clang/include/clang/Driver/Job.h
    clang/lib/Driver/Job.cpp
    clang/unittests/Driver/ToolChainTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Job.h b/clang/include/clang/Driver/Job.h
index 138ffc331a2f4..8b287638a271d 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_DRIVER_JOB_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -119,8 +120,8 @@ class Command {
   /// argument, which will be the executable).
   llvm::opt::ArgStringList Arguments;
 
-  /// The list of program arguments which are inputs.
-  llvm::opt::ArgStringList InputFilenames;
+  /// The list of program inputs.
+  std::vector<InputInfo> InputInfoList;
 
   /// The list of program arguments which are outputs. May be empty.
   std::vector<std::string> OutputFilenames;
@@ -207,9 +208,7 @@ class Command {
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
-  const llvm::opt::ArgStringList &getInputFilenames() const {
-    return InputFilenames;
-  }
+  const std::vector<InputInfo> &getInputInfos() const { return InputInfoList; }
 
   const std::vector<std::string> &getOutputFilenames() const {
     return OutputFilenames;

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index e1b62d771578c..5b87106b6565d 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@ Command::Command(const Action &Source, const Tool &Creator,
       Executable(Executable), Arguments(Arguments) {
   for (const auto &II : Inputs)
     if (II.isFilename())
-      InputFilenames.push_back(II.getFilename());
+      InputInfoList.push_back(II);
   for (const auto &II : Outputs)
     if (II.isFilename())
       OutputFilenames.push_back(II.getFilename());
@@ -237,9 +237,10 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
         }
       }
 
-      auto Found = llvm::find_if(InputFilenames,
-                                 [&Arg](StringRef IF) { return IF == Arg; });
-      if (Found != InputFilenames.end() &&
+      auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
+        return II.getFilename() == Arg;
+      });
+      if (Found != InputInfoList.end() &&
           (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
         // Replace the input file name with the crashinfo's file name.
         OS << ' ';
@@ -302,8 +303,8 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
 
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
-    for (const char *Arg : InputFilenames)
-      llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
+    for (const auto &Arg : InputInfoList)
+      llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
     llvm::outs().flush();
   }
 }

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 87f476c98dc94..253c65d0e29fe 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@ TEST(ToolChainTest, CommandOutput) {
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);


        


More information about the cfe-commits mailing list