diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp index fdf6015508d94..2b6e6a09f1335 100644 --- a/clang/lib/Tooling/CompilationDatabase.cpp +++ b/clang/lib/Tooling/CompilationDatabase.cpp @@ -156,6 +156,7 @@ struct CompileJobAnalyzer { bool CollectChildren = Collect; switch (A->getKind()) { case driver::Action::CompileJobClass: + case driver::Action::PrecompileJobClass: CollectChildren = true; break; @@ -293,7 +294,8 @@ static bool stripPositionalArgs(std::vector Args, // -flto* flags make the BackendJobClass, which still needs analyzer. if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass || Cmd.getSource().getKind() == driver::Action::BackendJobClass || - Cmd.getSource().getKind() == driver::Action::CompileJobClass) { + Cmd.getSource().getKind() == driver::Action::CompileJobClass || + Cmd.getSource().getKind() == driver::Action::PrecompileJobClass) { CompileAnalyzer.run(&Cmd.getSource()); } } diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index 5173d472486bf..45062cf7c16f6 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -647,12 +647,30 @@ TEST(ParseFixedCompilationDatabase, HandlesPositionalArgs) { FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg); ASSERT_TRUE((bool)Database); ASSERT_TRUE(ErrorMsg.empty()); + std::vector Result = Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + ASSERT_THAT(Result[0].CommandLine, + ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source")); + EXPECT_EQ(2, Argc); +} + +TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsHeader) { + const char *Argv[] = {"1", "2", "--", "-xc++-header", + "-c", "somefile.h", "-DDEF3"}; + int Argc = std::size(Argv); + std::string ErrorMsg; + std::unique_ptr Database = + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg); + ASSERT_TRUE((bool)Database); + ASSERT_TRUE(ErrorMsg.empty()); std::vector Result = Database->getCompileCommands("source"); ASSERT_EQ(1ul, Result.size()); ASSERT_EQ(".", Result[0].Directory); ASSERT_THAT(Result[0].CommandLine, - ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source")); + ElementsAre(EndsWith("clang-tool"), "-xc++-header", "-c", + "-DDEF3", "source")); EXPECT_EQ(2, Argc); }