[clang] 241cceb - [Clang][Tooling] Accept preprocessed input files

J. Ryan Stinnett via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 8 04:45:11 PDT 2023


Author: J. Ryan Stinnett
Date: 2023-08-08T12:44:48+01:00
New Revision: 241cceb9af844ef7d7a87124407a04b0a64991fe

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

LOG: [Clang][Tooling] Accept preprocessed input files

This restores the tooling library's ability to accept invocations that take a
preprocessed file as the primary input.

Regressed by https://reviews.llvm.org/D105695
Fixes https://github.com/llvm/llvm-project/issues/63941

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

Added: 
    

Modified: 
    clang/lib/Tooling/Tooling.cpp
    clang/unittests/Tooling/ToolingTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 46a784e44b931a..dc82a1f3772dd2 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -147,6 +147,13 @@ getCC1Arguments(DiagnosticsEngine *Diagnostics,
     if (IsCC1Command(Job) && llvm::all_of(Job.getInputInfos(), IsSrcFile))
       CC1Jobs.push_back(&Job);
 
+  // If there are no jobs for source files, try checking again for a single job
+  // with any file type. This accepts a preprocessed file as input.
+  if (CC1Jobs.empty())
+    for (const driver::Command &Job : Jobs)
+      if (IsCC1Command(Job))
+        CC1Jobs.push_back(&Job);
+
   if (CC1Jobs.empty() ||
       (CC1Jobs.size() > 1 && !ignoreExtraCC1Commands(Compilation))) {
     SmallString<256> error_msg;

diff  --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index ebe03fda78f1ef..354af292a54108 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -449,6 +449,13 @@ TEST_F(CommandLineExtractorTest, AcceptSaveTemps) {
   EXPECT_NE(extractCC1Arguments(Args), nullptr);
 }
 
+TEST_F(CommandLineExtractorTest, AcceptPreprocessedInputFile) {
+  addFile("test.i", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0", "-c",
+                        "test.i"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
 TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
   addFile("test.c", "int main() {}\n");
   const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",


        


More information about the cfe-commits mailing list