From: Richard Smith Date: Mon, 18 May 2015 05:35:52 +0000 (+0000) Subject: [modules] Move implicit creation of ImportDecls for #includes transformed into module... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f804390611e593da49cbaebfafbed7963d3c5630;p=clang [modules] Move implicit creation of ImportDecls for #includes transformed into module imports from the frontend into Sema where it belongs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237555 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 2d8bb71ee1..9e017273cb 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1612,25 +1612,6 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, Module, ImportLoc); } - // Determine whether we're in the #include buffer for a module. The #includes - // in that buffer do not qualify as module imports; they're just an - // implementation detail of us building the module. - bool IsInModuleIncludes = !getLangOpts().CurrentModule.empty() && - getSourceManager().getFileID(ImportLoc) == - getSourceManager().getMainFileID(); - - // If this module import was due to an inclusion directive, create an - // implicit import declaration to capture it in the AST. - if (IsInclusionDirective && hasASTContext() && !IsInModuleIncludes) { - TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); - ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, - ImportLoc, Module, - Path.back().second); - TU->addDecl(ImportD); - if (Consumer) - Consumer->HandleImplicitImportDecl(ImportD); - } - LastModuleImportLoc = ImportLoc; LastModuleImportResult = ModuleLoadResult(Module, false); return LastModuleImportResult; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 8c079f8647..316700dc3d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -14113,7 +14113,26 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc, void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext); - // FIXME: Should we synthesize an ImportDecl here? + // Determine whether we're in the #include buffer for a module. The #includes + // in that buffer do not qualify as module imports; they're just an + // implementation detail of us building the module. + // + // FIXME: Should we even get ActOnModuleInclude calls for those? + bool IsInModuleIncludes = + TUKind == TU_Module && + getSourceManager().isWrittenInMainFile(DirectiveLoc); + + // If this module import was due to an inclusion directive, create an + // implicit import declaration to capture it in the AST. + if (!IsInModuleIncludes) { + TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); + ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, + DirectiveLoc, Mod, + DirectiveLoc); + TU->addDecl(ImportD); + Consumer.HandleImplicitImportDecl(ImportD); + } + getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, DirectiveLoc); VisibleModules.setVisible(Mod, DirectiveLoc); } diff --git a/test/Index/index-module.m b/test/Index/index-module.m index 2e30fbcf72..a973e91af8 100644 --- a/test/Index/index-module.m +++ b/test/Index/index-module.m @@ -8,8 +8,8 @@ int glob; // RUN: -Xclang -fdisable-module-hash | FileCheck %s // CHECK-NOT: [indexDeclaration] -// CHECK: [importedASTFile]: [[PCM:.*[/\\]DependsOnModule\.pcm]] | loc: 2:2 | name: "DependsOnModule" | isImplicit: 1 -// CHECK-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h | name: "DependsOnModule/DependsOnModule.h" | hash loc: 2:1 | isImport: 0 | isAngled: 1 | isModule: 1 +// CHECK: [ppIncludedFile]: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h | name: "DependsOnModule/DependsOnModule.h" | hash loc: 2:1 | isImport: 0 | isAngled: 1 | isModule: 1 +// CHECK-NEXT: [importedASTFile]: [[PCM:.*[/\\]DependsOnModule\.pcm]] | loc: 2:1 | name: "DependsOnModule" | isImplicit: 1 // CHECK-NOT: [indexDeclaration] // CHECK: [importedASTFile]: [[PCM]] | loc: 3:1 | name: "DependsOnModule" | isImplicit: 0 // CHECK-NEXT: [indexDeclaration]: kind: variable | name: glob | {{.*}} | loc: 4:5 @@ -25,7 +25,7 @@ int glob; // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Frameworks[/\\]SubFramework\.framework[/\\]Headers[/\\]SubFramework\.h]] | {{.*}} | hash loc: | {{.*}} | module: DependsOnModule.SubFramework // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_OTHER_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]Frameworks/SubFramework\.framework/Headers/Other\.h]] | name: "SubFramework/Other.h" | hash loc: [[DMOD_SUB_H]]:1:1 | isImport: 0 | isAngled: 0 | isModule: 0 | module: DependsOnModule.SubFramework.Other // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_PRIVATE_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]PrivateHeaders[/\\]DependsOnModulePrivate.h]] | {{.*}} | hash loc: | {{.*}} | module: DependsOnModule.Private.DependsOnModule -// CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache{{[/\\]}}Module.pcm | loc: [[DMOD_MODULE_H]]:1:2 | name: "Module" | isImplicit: 1 +// CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache{{[/\\]}}Module.pcm | loc: [[DMOD_MODULE_H]]:1:1 | name: "Module" | isImplicit: 1 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_other | {{.*}} | loc: [[DMOD_OTHER_H]]:1:5 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: template | {{.*}} | loc: [[DMOD_NOT_CXX_H]]:1:12 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: sub_framework | {{.*}} | loc: [[DMOD_SUB_H]]:2:8 diff --git a/test/Index/index-pch-with-module.m b/test/Index/index-pch-with-module.m index ef0392ee96..53bac1e446 100644 --- a/test/Index/index-pch-with-module.m +++ b/test/Index/index-pch-with-module.m @@ -27,5 +27,5 @@ int glob; // CHECK-PCH: [enteredMainFile]: {{.*[/\\]}}index-pch-with-module.m // CHECK-PCH: [startedTranslationUnit] -// CHECK-PCH: [importedASTFile]: {{.*}}.cache{{[/\\]}}DependsOnModule.pcm | loc: 5:2 | name: "DependsOnModule" | isImplicit: 1 +// CHECK-PCH: [importedASTFile]: {{.*}}.cache{{[/\\]}}DependsOnModule.pcm | loc: 5:1 | name: "DependsOnModule" | isImplicit: 1 // CHECK-PCH: [indexDeclaration]: kind: variable | name: pch_glob | {{.*}} | loc: 6:12