Remove unnecessary mapping from SourceLocation to Module.

When we parse a redefinition of an entity for which we have a hidden existing
declaration, make it visible in the current module instead of mapping the
current source location to its containing module.

llvm-svn: 302842
This commit is contained in:
Richard Smith 2017-05-11 23:11:16 +00:00
parent bb78837e4d
commit 858e0e0a42
4 changed files with 18 additions and 14 deletions

View File

@ -1456,6 +1456,11 @@ private:
/// The modules we're currently parsing.
llvm::SmallVector<ModuleScope, 16> ModuleScopes;
/// Get the module whose scope we are currently within.
Module *getCurrentModule() const {
return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
}
VisibleModuleSet VisibleModules;
Module *CachedFakeTopLevelModule;
@ -1466,7 +1471,7 @@ public:
/// \brief Make a merged definition of an existing hidden definition \p ND
/// visible at the specified location.
void makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc);
void makeMergedDefinitionVisible(NamedDecl *ND);
bool isModuleVisible(Module *M) { return VisibleModules.isVisible(M); }

View File

@ -2127,7 +2127,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
New->setTypeSourceInfo(OldTD->getTypeSourceInfo());
// Make the old tag definition visible.
makeMergedDefinitionVisible(Hidden, NewTag->getLocation());
makeMergedDefinitionVisible(Hidden);
// If this was an unscoped enumeration, yank all of its enumerators
// out of the scope.
@ -3929,8 +3929,8 @@ bool Sema::checkVarDeclRedefinition(VarDecl *Old, VarDecl *New) {
// Make the canonical definition visible.
if (auto *OldTD = Old->getDescribedVarTemplate())
makeMergedDefinitionVisible(OldTD, New->getLocation());
makeMergedDefinitionVisible(Old, New->getLocation());
makeMergedDefinitionVisible(OldTD);
makeMergedDefinitionVisible(Old);
return false;
} else {
Diag(New->getLocation(), diag::err_redefinition) << New;
@ -11884,9 +11884,8 @@ Sema::CheckForFunctionRedefinition(FunctionDecl *FD,
Definition->getNumTemplateParameterLists())) {
SkipBody->ShouldSkip = true;
if (auto *TD = Definition->getDescribedFunctionTemplate())
makeMergedDefinitionVisible(TD, FD->getLocation());
makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition),
FD->getLocation());
makeMergedDefinitionVisible(TD);
makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition));
return;
}
@ -13540,7 +13539,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
// we already have. Make the existing definition visible and
// use it in place of this one.
SkipBody->ShouldSkip = true;
makeMergedDefinitionVisible(Hidden, KWLoc);
makeMergedDefinitionVisible(Hidden);
return Def;
} else if (!IsExplicitSpecializationAfterInstantiation) {
// A redeclaration in function prototype scope in C isn't

View File

@ -1382,8 +1382,8 @@ Module *Sema::getOwningModule(Decl *Entity) {
return M;
}
void Sema::makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc) {
if (auto *M = PP.getModuleContainingLocation(Loc))
void Sema::makeMergedDefinitionVisible(NamedDecl *ND) {
if (auto *M = getCurrentModule())
Context.mergeDefinitionIntoModule(ND, M);
else
// We're not building a module; just make the definition visible.
@ -1393,7 +1393,7 @@ void Sema::makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc) {
// visible too. They're not (necessarily) within a mergeable DeclContext.
if (auto *TD = dyn_cast<TemplateDecl>(ND))
for (auto *Param : *TD->getTemplateParameters())
makeMergedDefinitionVisible(Param, Loc);
makeMergedDefinitionVisible(Param);
}
/// \brief Find the module in which the given declaration was defined.

View File

@ -1330,8 +1330,8 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
auto *Tmpl = cast<CXXRecordDecl>(Hidden)->getDescribedClassTemplate();
assert(Tmpl && "original definition of a class template is not a "
"class template?");
makeMergedDefinitionVisible(Hidden, KWLoc);
makeMergedDefinitionVisible(Tmpl, KWLoc);
makeMergedDefinitionVisible(Hidden);
makeMergedDefinitionVisible(Tmpl);
return Def;
}
@ -7431,7 +7431,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
NamedDecl *Hidden = nullptr;
if (Def && SkipBody && !hasVisibleDefinition(Def, &Hidden)) {
SkipBody->ShouldSkip = true;
makeMergedDefinitionVisible(Hidden, KWLoc);
makeMergedDefinitionVisible(Hidden);
// From here on out, treat this as just a redeclaration.
TUK = TUK_Declaration;
} else if (Def) {