summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-10-11 00:36:56 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-10-11 00:36:56 +0000
commit18057cb34c83a11889e0cced9ab43aa57875634f (patch)
tree89de9c79b7e00e27f9921337cabedcc2be50abcb /clang/lib/Sema/SemaDecl.cpp
parent922973a46644b6bd1f86780f3cd36d79c5ef2003 (diff)
downloadbcm5719-llvm-18057cb34c83a11889e0cced9ab43aa57875634f.tar.gz
bcm5719-llvm-18057cb34c83a11889e0cced9ab43aa57875634f.zip
[Modules TS] Diagnose missing/duplicate module-declaration.
llvm-svn: 315397
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 84cae84dec7..c2d480c34ff 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16176,9 +16176,19 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc,
return nullptr;
}
+ assert(ModuleScopes.size() == 1 && "expected to be at global module scope");
+
// FIXME: Most of this work should be done by the preprocessor rather than
// here, in order to support macro import.
+ // Only one module-declaration is permitted per source file.
+ if (ModuleScopes.back().Module->Kind == Module::ModuleInterfaceUnit) {
+ Diag(ModuleLoc, diag::err_module_redeclaration);
+ Diag(VisibleModules.getImportLoc(ModuleScopes.back().Module),
+ diag::note_prev_module_declaration);
+ return nullptr;
+ }
+
// Flatten the dots in a module name. Unlike Clang's hierarchical module map
// modules, the dots here are just another character that can appear in a
// module name.
@@ -16189,8 +16199,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc,
ModuleName += Piece.first->getName();
}
- // FIXME: If we've already seen a module-declaration, report an error.
-
// If a module name was explicitly specified on the command line, it must be
// correct.
if (!getLangOpts().CurrentModule.empty() &&
@@ -16205,8 +16213,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc,
auto &Map = PP.getHeaderSearchInfo().getModuleMap();
Module *Mod;
- assert(ModuleScopes.size() == 1 && "expected to be at global module scope");
-
switch (MDK) {
case ModuleDeclKind::Interface: {
// We can't have parsed or imported a definition of this module or parsed a
@@ -16240,7 +16246,9 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc,
/*IsIncludeDirective=*/false);
if (!Mod) {
Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName;
- return nullptr;
+ // Create an empty module interface unit for error recovery.
+ Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName,
+ ModuleScopes.front().Module);
}
break;
}
OpenPOWER on IntegriCloud