Skip to content

Commit

Permalink
[Clang][Tooling] Accept preprocessed input files
Browse files Browse the repository at this point in the history
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 #63941

Differential Revision: https://reviews.llvm.org/D157011
  • Loading branch information
jryans committed Aug 8, 2023
1 parent 7542477 commit 241cceb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Tooling/ToolingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 241cceb

Please sign in to comment.