@@ -653,18 +653,23 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
653653 }
654654
655655 IncludeStructure Includes;
656+ include_cleaner::PragmaIncludes PI;
656657 // If we are using a preamble, copy existing includes.
657658 if (Preamble) {
658659 Includes = Preamble->Includes ;
659660 Includes.MainFileIncludes = Patch->preambleIncludes ();
660661 // Replay the preamble includes so that clang-tidy checks can see them.
661662 ReplayPreamble::attach (Patch->preambleIncludes (), *Clang,
662663 Patch->modifiedBounds ());
664+ PI = *Preamble->Pragmas ;
663665 }
664666 // Important: collectIncludeStructure is registered *after* ReplayPreamble!
665667 // Otherwise we would collect the replayed includes again...
666668 // (We can't *just* use the replayed includes, they don't have Resolved path).
667669 Includes.collect (*Clang);
670+ // Same for pragma-includes, we're already inheriting preamble includes, so we
671+ // should only receive callbacks for non-preamble mainfile includes.
672+ PI.record (*Clang);
668673 // Copy over the macros in the preamble region of the main file, and combine
669674 // with non-preamble macros below.
670675 MainFileMacros Macros;
@@ -735,7 +740,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
735740 ParsedAST Result (Filename, Inputs.Version , std::move (Preamble),
736741 std::move (Clang), std::move (Action), std::move (Tokens),
737742 std::move (Macros), std::move (Marks), std::move (ParsedDecls),
738- std::move (Diags), std::move (Includes));
743+ std::move (Diags), std::move (Includes), std::move (PI) );
739744 llvm::move (getIncludeCleanerDiags (Result, Inputs.Contents ),
740745 std::back_inserter (Result.Diags ));
741746 return std::move (Result);
@@ -828,23 +833,21 @@ ParsedAST::ParsedAST(PathRef TUPath, llvm::StringRef Version,
828833 syntax::TokenBuffer Tokens, MainFileMacros Macros,
829834 std::vector<PragmaMark> Marks,
830835 std::vector<Decl *> LocalTopLevelDecls,
831- std::vector<Diag> Diags, IncludeStructure Includes)
836+ std::vector<Diag> Diags, IncludeStructure Includes,
837+ include_cleaner::PragmaIncludes PI)
832838 : TUPath(TUPath), Version(Version), Preamble(std::move(Preamble)),
833839 Clang (std::move(Clang)), Action(std::move(Action)),
834840 Tokens(std::move(Tokens)), Macros(std::move(Macros)),
835841 Marks(std::move(Marks)), Diags(std::move(Diags)),
836842 LocalTopLevelDecls(std::move(LocalTopLevelDecls)),
837- Includes(std::move(Includes)) {
838- Resolver = std::make_unique<HeuristicResolver>(getASTContext ());
843+ Includes(std::move(Includes)), PI(std::move(PI)),
844+ Resolver( std::make_unique<HeuristicResolver>(getASTContext())) {
839845 assert (this ->Clang );
840846 assert (this ->Action );
841847}
842848
843- std::shared_ptr<const include_cleaner::PragmaIncludes>
844- ParsedAST::getPragmaIncludes () const {
845- if (!Preamble)
846- return nullptr ;
847- return Preamble->Pragmas ;
849+ const include_cleaner::PragmaIncludes &ParsedAST::getPragmaIncludes () const {
850+ return PI;
848851}
849852
850853std::optional<llvm::StringRef> ParsedAST::preambleVersion () const {
0 commit comments