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

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 26 04:57:24 PDT 2021


jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 <https://reviews.llvm.org/D106787>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106788

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


Index: clang/unittests/Driver/ToolChainTest.cpp
===================================================================
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   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);
Index: clang/lib/Driver/Job.cpp
===================================================================
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@
       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 @@
         }
       }
 
-      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::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();
   }
 }
Index: clang/include/clang/Driver/Job.h
===================================================================
--- clang/include/clang/Driver/Job.h
+++ 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 @@
   /// 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 @@
 
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106788.361622.patch
Type: text/x-patch
Size: 3494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210726/106063ea/attachment.bin>


More information about the cfe-commits mailing list