From 4b3e7388d1a90f3e20a90d5624fe54dccca2610f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 11 Oct 2016 13:57:36 +0000 Subject: [modules] PR28752: Do not instantiate variable declarations which are not visible. https://reviews.llvm.org/D24508 Patch developed in collaboration with Richard Smith! llvm-svn: 283882 --- clang/lib/Serialization/ASTReaderDecl.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'clang/lib/Serialization/ASTReaderDecl.cpp') diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 19113da7e3c..864eaf02b02 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1216,6 +1216,7 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { VD->VarDeclBits.TSCSpec = Record[Idx++]; VD->VarDeclBits.InitStyle = Record[Idx++]; if (!isa(VD)) { + VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = Record[Idx++]; VD->NonParmVarDeclBits.ExceptionVar = Record[Idx++]; VD->NonParmVarDeclBits.NRVOVariable = Record[Idx++]; VD->NonParmVarDeclBits.CXXForRangeDecl = Record[Idx++]; @@ -3067,6 +3068,34 @@ void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, } namespace clang { +template<> +void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, + Redeclarable *D, + Decl *Previous, Decl *Canon) { + VarDecl *VD = static_cast(D); + VarDecl *PrevVD = cast(Previous); + D->RedeclLink.setPrevious(PrevVD); + D->First = PrevVD->First; + + + // We should keep at most one definition on the chain. + if (VD->isThisDeclarationADefinition()) { + for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { + // If we find an already demoted definition, this we already visited this + // part of the chain. Reduces the loop from quadratic-time to linear-time. + if (CurD->isThisDeclarationADemotedDefinition()) { + VD->demoteThisDefinitionToDeclaration(); + break; + } + if (CurD->isThisDeclarationADefinition()) { + // If we found another definition on the chain, demote the current one. + VD->demoteThisDefinitionToDeclaration(); + break; + } + } + } +} + template<> void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, Redeclarable *D, -- cgit v1.2.3