diff options
author | Vassil Vassilev <v.g.vassilev@gmail.com> | 2016-10-11 13:57:36 +0000 |
---|---|---|
committer | Vassil Vassilev <v.g.vassilev@gmail.com> | 2016-10-11 13:57:36 +0000 |
commit | 4b3e7388d1a90f3e20a90d5624fe54dccca2610f (patch) | |
tree | e0456da083480b6cfbeb8876c417f63657291aed /clang/lib/Serialization/ASTReaderDecl.cpp | |
parent | 092cfc597f11a8544c6a9616bbae3e1f727838e0 (diff) | |
download | bcm5719-llvm-4b3e7388d1a90f3e20a90d5624fe54dccca2610f.tar.gz bcm5719-llvm-4b3e7388d1a90f3e20a90d5624fe54dccca2610f.zip |
[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
Diffstat (limited to 'clang/lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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<ParmVarDecl>(VD)) { + VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = Record[Idx++]; VD->NonParmVarDeclBits.ExceptionVar = Record[Idx++]; VD->NonParmVarDeclBits.NRVOVariable = Record[Idx++]; VD->NonParmVarDeclBits.CXXForRangeDecl = Record[Idx++]; @@ -3069,6 +3070,34 @@ void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, namespace clang { template<> void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, + Redeclarable<VarDecl> *D, + Decl *Previous, Decl *Canon) { + VarDecl *VD = static_cast<VarDecl*>(D); + VarDecl *PrevVD = cast<VarDecl>(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<FunctionDecl> *D, Decl *Previous, Decl *Canon) { FunctionDecl *FD = static_cast<FunctionDecl*>(D); |