diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp index 1d10348430c28..ac16803b46783 100644 --- a/clang-tools-extra/clang-move/Move.cpp +++ b/clang-tools-extra/clang-move/Move.cpp @@ -133,7 +133,8 @@ class FindAllIncludes : public PPCallbacks { CharSourceRange FilenameRange, OptionalFileEntryRef /*File*/, StringRef SearchPath, StringRef /*RelativePath*/, - const Module * /*Imported*/, + const Module * /*SuggestedModule*/, + bool /*ModuleImported*/, SrcMgr::CharacteristicKind /*FileType*/) override { if (auto FileEntry = SM.getFileEntryRefForID(SM.getFileID(HashLoc))) MoveTool->addIncludes(FileName, IsAngled, SearchPath, diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index 5ecd4fb19131e..5e2cc207560d3 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -166,12 +166,12 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective( SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef IncludedFile, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) { - if (Imported) { + if (ModuleImported) { serialization::ModuleFile *MF = Compiler.getASTReader()->getModuleManager().lookup( - *Imported->getASTFile()); + *SuggestedModule->getASTFile()); handleModuleFile(MF); } parseToLocation(DirectiveLoc); diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h index 3f6abc315e5b9..0742c21bc4372 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h @@ -69,7 +69,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks { bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef IncludedFile, StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp index 084e44a714d1f..fb1e0e82a3149 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -29,7 +29,8 @@ class KernelNameRestrictionPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FileNameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -61,7 +62,7 @@ void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM, void KernelNameRestrictionPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &, StringRef FileName, bool, CharSourceRange, OptionalFileEntryRef, StringRef, StringRef, const Module *, - SrcMgr::CharacteristicKind) { + bool, SrcMgr::CharacteristicKind) { IncludeDirective ID = {HashLoc, FileName}; IncludeDirectives.push_back(std::move(ID)); } diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp index 61d89cf308130..09ba79f055752 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -26,7 +26,8 @@ class SuspiciousIncludePPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; private: @@ -51,8 +52,8 @@ void SuspiciousIncludeCheck::registerPPCallbacks( void SuspiciousIncludePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import) return; diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp index bdd72f85e2a27..4246c8c574c50 100644 --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -27,7 +27,8 @@ class IncludeOrderPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -81,8 +82,8 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) { void IncludeOrderPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { // We recognize the first include as a special main module header and want // to leave it in the top position. IncludeDirective ID = {HashLoc, FilenameRange, std::string(FileName), diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp index 3451d3474fd90..b656917071a6c 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp @@ -33,7 +33,8 @@ class RestrictedIncludesPPCallbacks StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; private: @@ -45,14 +46,14 @@ class RestrictedIncludesPPCallbacks void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { // Compiler provided headers are allowed (e.g stddef.h). if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir) return; portability::RestrictedIncludesPPCallbacks::InclusionDirective( HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, - RelativePath, Imported, FileType); + RelativePath, SuggestedModule, ModuleImported, FileType); } void RestrictSystemLibcHeadersCheck::registerPPCallbacks( diff --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp index bebd6e390ed53..fadfdc869d37b 100644 --- a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp @@ -83,7 +83,7 @@ class CyclicDependencyCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation, const Token &, StringRef FilePath, bool, CharSourceRange Range, OptionalFileEntryRef File, StringRef, StringRef, - const Module *, + const Module *, bool, SrcMgr::CharacteristicKind FileType) override { if (FileType != clang::SrcMgr::C_User) return; diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp index 030a781e2099b..6d287eb3642df 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -32,7 +32,8 @@ class IncludeModernizePPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; private: @@ -178,8 +179,8 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks( void IncludeModernizePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { // If we don't want to warn for non-main file reports and this is one, skip // it. diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp index b197c22dca410..0b47ed316ca27 100644 --- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp @@ -117,7 +117,8 @@ class MacroToEnumCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { clearCurrentEnum(HashLoc); } diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp index 9ee0b4e6d3ccb..db5693e3b7cb7 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -21,8 +21,8 @@ namespace clang::tidy::portability { void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) { SmallString<256> FullPath; llvm::sys::path::append(FullPath, SearchPath); diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h index ad18e6f411dbb..60fae5e73a602 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -50,7 +50,8 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; diff --git a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp index d1f41e0ec79e2..67147164946ab 100644 --- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp @@ -47,7 +47,8 @@ class DuplicateIncludeCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void MacroDefined(const Token &MacroNameTok, @@ -76,8 +77,8 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc, void DuplicateIncludeCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { if (llvm::is_contained(Files.back(), FileName)) { // We want to delete the entire line, so make sure that [Start,End] covers // everything. diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index d0b7474992abd..b53016f331b79 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -25,7 +25,8 @@ class IncludeInserterCallback : public PPCallbacks { bool IsAngled, CharSourceRange FileNameRange, OptionalFileEntryRef /*IncludedFile*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, - const Module * /*ImportedModule*/, + const Module * /*SuggestedModule*/, + bool /*ModuleImported*/, SrcMgr::CharacteristicKind /*FileType*/) override { Inserter->addInclude(FileNameRef, IsAngled, HashLocation, IncludeToken.getEndLoc()); diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index 076e636e0e281..75f8668e7bef0 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -41,7 +41,8 @@ class IncludeStructure::RecordHeaders : public PPCallbacks { OptionalFileEntryRef File, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, - const clang::Module * /*Imported*/, + const clang::Module * /*SuggestedModule*/, + bool /*ModuleImported*/, SrcMgr::CharacteristicKind FileKind) override { auto MainFID = SM.getMainFileID(); // If an include is part of the preamble patch, translate #line directives. diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 14a91797f4d2e..bbb0e2c77b3f3 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -244,7 +244,7 @@ class ReplayPreamble : private PPCallbacks { SynthesizedFilenameTok.getEndLoc()) .toCharRange(SM), File, "SearchPath", "RelPath", - /*Imported=*/nullptr, Inc.FileKind); + /*SuggestedModule=*/nullptr, /*ModuleImported=*/false, Inc.FileKind); if (File) Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind); } diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp index 5d56285a83961..ed56c2a9d2e81 100644 --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -89,7 +89,8 @@ struct IncludeGraphCollector : public PPCallbacks { llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, - llvm::StringRef RelativePath, const Module *Imported, + llvm::StringRef RelativePath, + const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { auto IncludeURI = toURI(File); if (!IncludeURI) diff --git a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp index 472fe30ee46ed..147d9abe69137 100644 --- a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp @@ -72,7 +72,7 @@ struct ReplayPreamblePPCallback : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef, - StringRef, StringRef, const clang::Module *, + StringRef, StringRef, const clang::Module *, bool, SrcMgr::CharacteristicKind) override { Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled, FilenameRange); diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index c93c56adf650d..78a4df6cc40ea 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -65,7 +65,8 @@ class PPRecorder : public PPCallbacks { StringRef SpelledFilename, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind) override { if (!Active) return; @@ -214,7 +215,8 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { OptionalFileEntryRef File, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, - const clang::Module * /*Imported*/, + const clang::Module * /*SuggestedModule*/, + bool /*ModuleImported*/, SrcMgr::CharacteristicKind FileKind) override { FileID HashFID = SM.getFileID(HashLoc); int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc)); diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp index 1e8b0aa37ca30..0e76c539aa3c8 100644 --- a/clang-tools-extra/modularize/CoverageChecker.cpp +++ b/clang-tools-extra/modularize/CoverageChecker.cpp @@ -90,7 +90,8 @@ class CoverageCheckerCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { Checker.collectUmbrellaHeaderHeader(File->getName()); } diff --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp index 7557fb177ceb4..85e3aab041e49 100644 --- a/clang-tools-extra/modularize/PreprocessorTracker.cpp +++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -730,15 +730,14 @@ class PreprocessorCallbacks : public clang::PPCallbacks { ~PreprocessorCallbacks() override {} // Overridden handlers. - void InclusionDirective(clang::SourceLocation HashLoc, - const clang::Token &IncludeTok, - llvm::StringRef FileName, bool IsAngled, - clang::CharSourceRange FilenameRange, - clang::OptionalFileEntryRef File, - llvm::StringRef SearchPath, - llvm::StringRef RelativePath, - const clang::Module *Imported, - clang::SrcMgr::CharacteristicKind FileType) override; + void + InclusionDirective(clang::SourceLocation HashLoc, + const clang::Token &IncludeTok, llvm::StringRef FileName, + bool IsAngled, clang::CharSourceRange FilenameRange, + clang::OptionalFileEntryRef File, + llvm::StringRef SearchPath, llvm::StringRef RelativePath, + const clang::Module *SuggestedModule, bool ModuleImported, + clang::SrcMgr::CharacteristicKind FileType) override; void FileChanged(clang::SourceLocation Loc, clang::PPCallbacks::FileChangeReason Reason, clang::SrcMgr::CharacteristicKind FileType, @@ -1275,7 +1274,8 @@ void PreprocessorCallbacks::InclusionDirective( llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, clang::OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, - const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) { + const clang::Module *SuggestedModule, bool ModuleImported, + clang::SrcMgr::CharacteristicKind FileType) { int DirectiveLine, DirectiveColumn; std::string HeaderPath = getSourceLocationFile(PP, HashLoc); getSourceLocationLineAndColumn(PP, HashLoc, DirectiveLine, DirectiveColumn); diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp index a59a8278682b2..3bb30fd15b2e1 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -135,7 +135,8 @@ void PPCallbacksTracker::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, - const Module *Imported, SrcMgr::CharacteristicKind FileType) { + const Module *SuggestedModule, bool ModuleImported, + SrcMgr::CharacteristicKind FileType) { beginCallback("InclusionDirective"); appendArgument("HashLoc", HashLoc); appendArgument("IncludeTok", IncludeTok); @@ -145,7 +146,8 @@ void PPCallbacksTracker::InclusionDirective( appendArgument("File", File); appendFilePathArgument("SearchPath", SearchPath); appendFilePathArgument("RelativePath", RelativePath); - appendArgument("Imported", Imported); + appendArgument("SuggestedModule", SuggestedModule); + appendArgument("ModuleImported", ModuleImported); } // Callback invoked whenever there was an explicit module-import diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.h b/clang-tools-extra/pp-trace/PPCallbacksTracker.h index c195a72b08c1a..04590a919369a 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -95,7 +95,8 @@ class PPCallbacksTracker : public PPCallbacks { llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, - llvm::StringRef RelativePath, const Module *Imported, + llvm::StringRef RelativePath, + const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override; diff --git a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp index db0b2c89430a2..ea9896e1cfde2 100644 --- a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp +++ b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp @@ -59,7 +59,8 @@ // CHECK-NEXT: File: "{{.*}}{{[/\\]}}Inputs/Level1A.h" // CHECK-NEXT: SearchPath: "{{.*}}{{[/\\]}}pp-trace" // CHECK-NEXT: RelativePath: "Inputs/Level1A.h" -// CHECK-NEXT: Imported: (null) +// CHECK-NEXT: SuggestedModule: (null) +// CHECK-NEXT: ModuleImported: false // CHECK-NEXT: - Callback: FileChanged // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}Inputs/Level1A.h:1:1" // CHECK-NEXT: Reason: EnterFile @@ -74,7 +75,8 @@ // CHECK-NEXT: File: "{{.*}}{{[/\\]}}Inputs/Level2A.h" // CHECK-NEXT: SearchPath: "{{.*}}{{[/\\]}}Inputs" // CHECK-NEXT: RelativePath: "Level2A.h" -// CHECK-NEXT: Imported: (null) +// CHECK-NEXT: SuggestedModule: (null) +// CHECK-NEXT: ModuleImported: false // CHECK-NEXT: - Callback: FileChanged // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}Inputs/Level2A.h:1:1" // CHECK-NEXT: Reason: EnterFile @@ -105,7 +107,8 @@ // CHECK-NEXT: File: "{{.*}}{{[/\\]}}Inputs/Level1B.h" // CHECK-NEXT: SearchPath: "{{.*}}{{[/\\]}}pp-trace" // CHECK-NEXT: RelativePath: "Inputs/Level1B.h" -// CHECK-NEXT: Imported: (null) +// CHECK-NEXT: SuggestedModule: (null) +// CHECK-NEXT: ModuleImported: false // CHECK-NEXT: - Callback: FileChanged // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}Inputs/Level1B.h:1:1" // CHECK-NEXT: Reason: EnterFile @@ -120,7 +123,8 @@ // CHECK-NEXT: File: "{{.*}}{{[/\\]}}Inputs/Level2B.h" // CHECK-NEXT: SearchPath: "{{.*}}{{[/\\]}}Inputs" // CHECK-NEXT: RelativePath: "Level2B.h" -// CHECK-NEXT: Imported: (null) +// CHECK-NEXT: SuggestedModule: (null) +// CHECK-NEXT: ModuleImported: false // CHECK-NEXT: - Callback: FileChanged // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}Inputs/Level2B.h:1:1" // CHECK-NEXT: Reason: EnterFile diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index e3942af7be280..dfc74b52686f1 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -127,8 +127,10 @@ class PPCallbacks { /// \param RelativePath The path relative to SearchPath, at which the include /// file was found. This is equal to FileName except for framework includes. /// - /// \param Imported The module, whenever an inclusion directive was - /// automatically turned into a module import or null otherwise. + /// \param SuggestedModule The module suggested for this header, if any. + /// + /// \param ModuleImported Whether this include was translated into import of + /// \p SuggestedModule. /// /// \param FileType The characteristic kind, indicates whether a file or /// directory holds normal user code, system code, or system code which is @@ -139,7 +141,8 @@ class PPCallbacks { bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) {} /// Callback invoked whenever a submodule was entered. @@ -473,14 +476,15 @@ class PPChainedCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, - Imported, FileType); + SuggestedModule, ModuleImported, FileType); Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, - Imported, FileType); + SuggestedModule, ModuleImported, FileType); } void EnteredSubmodule(Module *M, SourceLocation ImportLoc, diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index 5ddf024186f86..437d8e4cc174e 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -532,7 +532,8 @@ class Token; StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, + const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override; diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h index 051363b075de9..13ad253086492 100644 --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -166,7 +166,8 @@ class ModuleDepCollectorPP final : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override; diff --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp index 8589869f6e2fb..c5d1e3ad5a205 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.cpp +++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -168,8 +168,8 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, void MacroPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { // Record the line location of the current included file. LastHashLoc = HashLoc; diff --git a/clang/lib/CodeGen/MacroPPCallbacks.h b/clang/lib/CodeGen/MacroPPCallbacks.h index 5af177d0c3fa2..5f468648da044 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.h +++ b/clang/lib/CodeGen/MacroPPCallbacks.h @@ -102,7 +102,8 @@ class MacroPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; /// Hook called whenever a macro definition is seen. diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 19abcac2befbd..369816e89e1d6 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -66,7 +66,8 @@ struct DepCollectorPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/ false, diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index b471471f3528a..20e5f233e224e 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -49,7 +49,8 @@ class DependencyGraphCallback : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override { @@ -68,8 +69,8 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, void DependencyGraphCallback::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { if (!File) return; diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index 939e611e54899..b88cb60ebdd2a 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -55,7 +55,8 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 62373b23b82ef..9b0ef30a14121 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -98,7 +98,8 @@ class MissingFileCollector : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { // File is std::nullopt if it wasn't found. // (We have some false negatives if PP recovered e.g. -> "foo") diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 7f5f669068230..a26d2c3ab8582 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -153,7 +153,8 @@ class PrintPPOutputPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void Ident(SourceLocation Loc, StringRef str) override; void PragmaMessage(SourceLocation Loc, StringRef Namespace, @@ -401,8 +402,8 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, void PrintPPOutputPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { // In -dI mode, dump #include directives prior to dumping their content or // interpretation. Similar for -fkeep-system-includes. if (DumpIncludeDirectives || (KeepSystemIncludes && isSystem(FileType))) { @@ -418,14 +419,14 @@ void PrintPPOutputPPCallbacks::InclusionDirective( } // When preprocessing, turn implicit imports into module import pragmas. - if (Imported) { + if (ModuleImported) { switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_include: case tok::pp_import: case tok::pp_include_next: MoveToLine(HashLoc, /*RequireStartOfLine=*/true); *OS << "#pragma clang module import " - << Imported->getFullModuleName(true) + << SuggestedModule->getFullModuleName(true) << " /* clang -E: implicit import for " << "#" << PP.getSpelling(IncludeTok) << " " << (IsAngled ? '<' : '"') << FileName << (IsAngled ? '>' : '"') diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index b6b37461089e4..1462058003b3d 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -75,7 +75,8 @@ class InclusionRewriter : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override; @@ -189,9 +190,10 @@ void InclusionRewriter::InclusionDirective( StringRef /*FileName*/, bool /*IsAngled*/, CharSourceRange /*FilenameRange*/, OptionalFileEntryRef /*File*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, - const Module *Imported, SrcMgr::CharacteristicKind FileType) { - if (Imported) { - auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported)); + const Module *SuggestedModule, bool ModuleImported, + SrcMgr::CharacteristicKind FileType) { + if (ModuleImported) { + auto P = ModuleIncludes.insert(std::make_pair(HashLoc, SuggestedModule)); (void)P; assert(P.second && "Unexpected revisitation of the same include directive"); } else diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index a980f4bcbae12..97f9c0ada91de 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -2253,26 +2253,27 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // FIXME: We do not have a good way to disambiguate C++ clang modules from // C++ standard modules (other than use/non-use of Header Units). - Module *SM = SuggestedModule.getModule(); - bool MaybeTranslateInclude = - Action == Enter && File && SM && !SM->isForBuilding(getLangOpts()); + Module *ModuleToImport = SuggestedModule.getModule(); + + bool MaybeTranslateInclude = Action == Enter && File && ModuleToImport && + !ModuleToImport->isForBuilding(getLangOpts()); // Maybe a usable Header Unit bool UsableHeaderUnit = false; - if (getLangOpts().CPlusPlusModules && SM && SM->isHeaderUnit()) { + if (getLangOpts().CPlusPlusModules && ModuleToImport && + ModuleToImport->isHeaderUnit()) { if (TrackGMFState.inGMF() || IsImportDecl) UsableHeaderUnit = true; else if (!IsImportDecl) { // This is a Header Unit that we do not include-translate - SuggestedModule = ModuleMap::KnownHeader(); - SM = nullptr; + ModuleToImport = nullptr; } } // Maybe a usable clang header module. bool UsableClangHeaderModule = - (getLangOpts().CPlusPlusModules || getLangOpts().Modules) && SM && - !SM->isHeaderUnit(); + (getLangOpts().CPlusPlusModules || getLangOpts().Modules) && + ModuleToImport && !ModuleToImport->isHeaderUnit(); // Determine whether we should try to import the module for this #include, if // there is one. Don't do so if precompiled module support is disabled or we @@ -2282,12 +2283,11 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // unavailable, diagnose the situation and bail out. // FIXME: Remove this; loadModule does the same check (but produces // slightly worse diagnostics). - if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(), - *SuggestedModule.getModule(), + if (checkModuleIsAvailable(getLangOpts(), getTargetInfo(), *ModuleToImport, getDiagnostics())) { Diag(FilenameTok.getLocation(), diag::note_implicit_top_level_module_import_here) - << SuggestedModule.getModule()->getTopLevelModuleName(); + << ModuleToImport->getTopLevelModuleName(); return {ImportAction::None}; } @@ -2295,7 +2295,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // FIXME: Should we have a second loadModule() overload to avoid this // extra lookup step? SmallVector, 2> Path; - for (Module *Mod = SM; Mod; Mod = Mod->Parent) + for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent) Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name), FilenameTok.getLocation())); std::reverse(Path.begin(), Path.end()); @@ -2306,12 +2306,12 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // Load the module to import its macros. We'll make the declarations // visible when the parser gets here. - // FIXME: Pass SuggestedModule in here rather than converting it to a path - // and making the module loader convert it back again. + // FIXME: Pass SM in here rather than converting it to a path and making the + // module loader convert it back again. ModuleLoadResult Imported = TheModuleLoader.loadModule( IncludeTok.getLocation(), Path, Module::Hidden, /*IsInclusionDirective=*/true); - assert((Imported == nullptr || Imported == SuggestedModule.getModule()) && + assert((Imported == nullptr || Imported == SM) && "the imported module is different than the suggested one"); if (Imported) { @@ -2323,8 +2323,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // was in the directory of an umbrella header, for instance), but no // actual module containing it exists (because the umbrella header is // incomplete). Treat this as a textual inclusion. - SuggestedModule = ModuleMap::KnownHeader(); - SM = nullptr; + ModuleToImport = nullptr; } else if (Imported.isConfigMismatch()) { // On a configuration mismatch, enter the header textually. We still know // that it's part of the corresponding module. @@ -2365,7 +2364,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // this file will have no effect. if (Action == Enter && File && !HeaderInfo.ShouldEnterIncludeFile(*this, *File, EnterOnce, - getLangOpts().Modules, SM, + getLangOpts().Modules, ModuleToImport, IsFirstIncludeOfFile)) { // C++ standard modules: // If we are not in the GMF, then we textually include only @@ -2380,7 +2379,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( if (UsableHeaderUnit && !getLangOpts().CompilingPCH) Action = TrackGMFState.inGMF() ? Import : Skip; else - Action = (SuggestedModule && !getLangOpts().CompilingPCH) ? Import : Skip; + Action = (ModuleToImport && !getLangOpts().CompilingPCH) ? Import : Skip; } // Check for circular inclusion of the main file. @@ -2400,8 +2399,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // FIXME: Use a different callback for a pp-import? Callbacks->InclusionDirective(HashLoc, IncludeTok, LookupFilename, isAngled, FilenameRange, File, SearchPath, RelativePath, - Action == Import ? SuggestedModule.getModule() - : nullptr, + SuggestedModule.getModule(), Action == Import, FileCharacter); if (Action == Skip && File) Callbacks->FileSkipped(*File, FilenameTok, FileCharacter); @@ -2412,7 +2410,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // If this is a C++20 pp-import declaration, diagnose if we didn't find any // module corresponding to the named header. - if (IsImportDecl && !SuggestedModule) { + if (IsImportDecl && !ModuleToImport) { Diag(FilenameTok, diag::err_header_import_not_header_unit) << OriginalFilename << File->getName(); return {ImportAction::None}; @@ -2517,8 +2515,8 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( switch (Action) { case Skip: // If we don't need to enter the file, stop now. - if (SM) - return {ImportAction::SkippedModuleImport, SM}; + if (ModuleToImport) + return {ImportAction::SkippedModuleImport, ModuleToImport}; return {ImportAction::None}; case IncludeLimitReached: @@ -2530,13 +2528,13 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // If this is a module import, make it visible if needed. assert(SM && "no module to import"); - makeModuleVisible(SM, EndLoc); + makeModuleVisible(ModuleToImport, EndLoc); if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp___include_macros) return {ImportAction::None}; - return {ImportAction::ModuleImport, SM}; + return {ImportAction::ModuleImport, ModuleToImport}; } case Enter: @@ -2573,13 +2571,14 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // Determine if we're switching to building a new submodule, and which one. // This does not apply for C++20 modules header units. - if (SM && !SM->isHeaderUnit()) { - if (SM->getTopLevelModule()->ShadowingModule) { + if (ModuleToImport && !ModuleToImport->isHeaderUnit()) { + if (ModuleToImport->getTopLevelModule()->ShadowingModule) { // We are building a submodule that belongs to a shadowed module. This // means we find header files in the shadowed module. - Diag(SM->DefinitionLoc, diag::err_module_build_shadowed_submodule) - << SM->getFullModuleName(); - Diag(SM->getTopLevelModule()->ShadowingModule->DefinitionLoc, + Diag(ModuleToImport->DefinitionLoc, + diag::err_module_build_shadowed_submodule) + << ModuleToImport->getFullModuleName(); + Diag(ModuleToImport->getTopLevelModule()->ShadowingModule->DefinitionLoc, diag::note_previous_definition); return {ImportAction::None}; } @@ -2591,21 +2590,22 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // that behaves the same as the header would behave in a compilation using // that PCH, which means we should enter the submodule. We need to teach // the AST serialization layer to deal with the resulting AST. - if (getLangOpts().CompilingPCH && SM->isForBuilding(getLangOpts())) + if (getLangOpts().CompilingPCH && + ModuleToImport->isForBuilding(getLangOpts())) return {ImportAction::None}; assert(!CurLexerSubmodule && "should not have marked this as a module yet"); - CurLexerSubmodule = SM; + CurLexerSubmodule = ModuleToImport; // Let the macro handling code know that any future macros are within // the new submodule. - EnterSubmodule(SM, EndLoc, /*ForPragma*/ false); + EnterSubmodule(ModuleToImport, EndLoc, /*ForPragma*/ false); // Let the parser know that any future declarations are within the new // submodule. // FIXME: There's no point doing this if we're handling a #__include_macros // directive. - return {ImportAction::ModuleBegin, SM}; + return {ImportAction::ModuleBegin, ModuleToImport}; } assert(!IsImportDecl && "failed to diagnose missing module for import decl"); diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index aab6a2bed89d9..be5aac7ef31b8 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -472,8 +472,8 @@ void PreprocessingRecord::MacroUndefined(const Token &Id, void PreprocessingRecord::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { @@ -506,10 +506,9 @@ void PreprocessingRecord::InclusionDirective( EndLoc = EndLoc.getLocWithOffset(-1); // the InclusionDirective expects // a token range. } - clang::InclusionDirective *ID = - new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled, - (bool)Imported, File, - SourceRange(HashLoc, EndLoc)); + clang::InclusionDirective *ID = new (*this) clang::InclusionDirective( + *this, Kind, FileName, !IsAngled, ModuleImported, File, + SourceRange(HashLoc, EndLoc)); addPreprocessedEntity(ID); } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 995d8b2899c8d..5a9e563c2d5b2 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -430,14 +430,14 @@ void ModuleDepCollectorPP::LexedFileChanged(FileID FID, void ModuleDepCollectorPP::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { - if (!File && !Imported) { + StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) { + if (!File && !ModuleImported) { // This is a non-modular include that HeaderSearch failed to find. Add it // here as `FileChanged` will never see it. MDC.addFileDep(FileName); } - handleImport(Imported); + handleImport(SuggestedModule); } void ModuleDepCollectorPP::moduleImport(SourceLocation ImportLoc, diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 17d393ef80842..05d88452209fb 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -261,12 +261,13 @@ class IndexPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { bool isImport = (IncludeTok.is(tok::identifier) && IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import); DataConsumer.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled, - Imported); + ModuleImported); } /// MacroDefined - This hook is called whenever a macro definition is seen. diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index e0a27b5111821..f3cdb1dfb2874 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -37,7 +37,8 @@ class InclusionDirectiveCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + StringRef RelativePath, const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override { this->HashLoc = HashLoc; this->IncludeTok = IncludeTok; @@ -47,7 +48,8 @@ class InclusionDirectiveCallbacks : public PPCallbacks { this->File = File; this->SearchPath = SearchPath.str(); this->RelativePath = RelativePath.str(); - this->Imported = Imported; + this->SuggestedModule = SuggestedModule; + this->ModuleImported = ModuleImported; this->FileType = FileType; } @@ -59,7 +61,8 @@ class InclusionDirectiveCallbacks : public PPCallbacks { OptionalFileEntryRef File; SmallString<16> SearchPath; SmallString<16> RelativePath; - const Module* Imported; + const Module *SuggestedModule; + bool ModuleImported; SrcMgr::CharacteristicKind FileType; };