Skip to content

Commit 241cceb

Browse files
committed
[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 #63941 Differential Revision: https://reviews.llvm.org/D157011
1 parent 7542477 commit 241cceb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/Tooling/Tooling.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ getCC1Arguments(DiagnosticsEngine *Diagnostics,
147147
if (IsCC1Command(Job) && llvm::all_of(Job.getInputInfos(), IsSrcFile))
148148
CC1Jobs.push_back(&Job);
149149

150+
// If there are no jobs for source files, try checking again for a single job
151+
// with any file type. This accepts a preprocessed file as input.
152+
if (CC1Jobs.empty())
153+
for (const driver::Command &Job : Jobs)
154+
if (IsCC1Command(Job))
155+
CC1Jobs.push_back(&Job);
156+
150157
if (CC1Jobs.empty() ||
151158
(CC1Jobs.size() > 1 && !ignoreExtraCC1Commands(Compilation))) {
152159
SmallString<256> error_msg;

clang/unittests/Tooling/ToolingTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ TEST_F(CommandLineExtractorTest, AcceptSaveTemps) {
449449
EXPECT_NE(extractCC1Arguments(Args), nullptr);
450450
}
451451

452+
TEST_F(CommandLineExtractorTest, AcceptPreprocessedInputFile) {
453+
addFile("test.i", "int main() {}\n");
454+
const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0", "-c",
455+
"test.i"};
456+
EXPECT_NE(extractCC1Arguments(Args), nullptr);
457+
}
458+
452459
TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
453460
addFile("test.c", "int main() {}\n");
454461
const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",

0 commit comments

Comments
 (0)