summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Frontend/ASTUnit.h3
-rw-r--r--clang/include/clang/Frontend/CompilerInstance.h3
-rw-r--r--clang/include/clang/Lex/ModuleLoader.h7
-rw-r--r--clang/lib/AST/Decl.cpp4
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp16
-rw-r--r--clang/lib/Lex/PPDirectives.cpp3
-rw-r--r--clang/lib/Lex/Preprocessor.cpp3
-rw-r--r--clang/lib/Sema/SemaDecl.cpp3
8 files changed, 30 insertions, 12 deletions
diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h
index d65da5d67bd..8feab307ea5 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -782,7 +782,8 @@ public:
bool serialize(raw_ostream &OS);
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility) {
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective) {
// ASTUnit doesn't know how to load modules (not that this matters).
return 0;
}
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
index 21f8eeead3d..b488cde6e6e 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -642,7 +642,8 @@ public:
/// }
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility);
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective);
};
} // end namespace clang
diff --git a/clang/include/clang/Lex/ModuleLoader.h b/clang/include/clang/Lex/ModuleLoader.h
index 0bd97b6bd4b..b2fb722b94d 100644
--- a/clang/include/clang/Lex/ModuleLoader.h
+++ b/clang/include/clang/Lex/ModuleLoader.h
@@ -48,10 +48,15 @@ public:
/// \param Visibility The visibility provided for the names in the loaded
/// module.
///
+ /// \param IsInclusionDirective Indicates that this module is being loaded
+ /// implicitly, due to the presence of an inclusion directive. Otherwise,
+ /// it is being loaded due to an import declaration.
+ ///
/// \returns If successful, returns the loaded module. Otherwise, returns
/// NULL to indicate that the module could not be loaded.
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility) = 0;
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective) = 0;
};
}
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 2f167eedd15..1ed149b68f2 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2657,9 +2657,7 @@ ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC,
Module *Imported,
SourceLocation EndLoc) {
void *Mem = C.Allocate(sizeof(ImportDecl) + sizeof(SourceLocation));
- ImportDecl *Import
- = new (Mem) ImportDecl(DC, ImportLoc, Imported,
- ArrayRef<SourceLocation>(&EndLoc, 1));
+ ImportDecl *Import = new (Mem) ImportDecl(DC, ImportLoc, Imported, EndLoc);
Import->setImplicit();
return Import;
}
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 746c00a3619..6a060e036fb 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -11,6 +11,7 @@
#include "clang/Sema/Sema.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
@@ -1070,7 +1071,8 @@ static void compileModule(CompilerInstance &ImportingInstance,
Module *CompilerInstance::loadModule(SourceLocation ImportLoc,
ModuleIdPath Path,
- Module::NameVisibilityKind Visibility) {
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective) {
// If we've already handled this import, just return the cached result.
// This one-element cache is important to eliminate redundant diagnostics
// when both the preprocessor and parser see the same import declaration.
@@ -1259,8 +1261,16 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc,
}
// Make the named module visible.
- if (Module)
- ModuleManager->makeModuleVisible(Module, Visibility);
+ ModuleManager->makeModuleVisible(Module, Visibility);
+
+ // If this module import was due to an inclusion directive, create an
+ // implicit import declaration to capture it in the AST.
+ if (IsInclusionDirective && hasASTContext()) {
+ TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
+ TU->addDecl(ImportDecl::CreateImplicit(getASTContext(), TU,
+ ImportLoc, Module,
+ Path.back().second));
+ }
LastModuleImportLoc = ImportLoc;
LastModuleImportResult = Module;
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 836d21b2047..b44a0a2934f 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1363,7 +1363,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
// If this was an #__include_macros directive, only make macros visible.
Module::NameVisibilityKind Visibility
= (IncludeKind == 3)? Module::MacrosVisible : Module::AllVisible;
- TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility);
+ TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility,
+ /*IsIncludeDirective=*/true);
return;
}
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 6cf34e226af..dea7efc7658 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -599,7 +599,8 @@ void Preprocessor::LexAfterModuleImport(Token &Result) {
// If we have a non-empty module path, load the named module.
if (!ModuleImportPath.empty())
(void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath,
- Module::MacrosVisible);
+ Module::MacrosVisible,
+ /*IsIncludeDirective=*/false);
}
void Preprocessor::AddCommentHandler(CommentHandler *Handler) {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 01c7906e800..fdb2cf5d964 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9893,7 +9893,8 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr,
DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) {
Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path,
- Module::AllVisible);
+ Module::AllVisible,
+ /*IsIncludeDirective=*/false);
if (!Mod)
return true;
OpenPOWER on IntegriCloud