diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-12-25 04:47:44 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-12-25 04:47:44 +0000 |
commit | eaf5ec43ec52f650a00254d1c20d51fb7671aead (patch) | |
tree | 4d86fbb0e475df5bf9bfa69f3fe06925538db368 /lib/AST/Decl.cpp | |
parent | dfb316613a40d0efc033c7bd0a49da59c915fc63 (diff) |
Revert r171048, "Cache visibility of decls."
It broke stage2.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171050 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index a3cdb401ea..a2c6da67f0 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -104,14 +104,8 @@ getLVForTemplateParameterList(const TemplateParameterList *Params) { return LV; } -/// Compute the linkage and visibility for the given declaration. -static LinkageInfo computeLVForDecl(const NamedDecl *D, bool OnlyTemplate); - -static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) { - if (!OnlyTemplate) - return D->getLinkageAndVisibility(); - return computeLVForDecl(D, OnlyTemplate); -} +/// getLVForDecl - Get the linkage and visibility for the given declaration. +static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate); /// \brief Get the most restrictive linkage for the types and /// declarations in the given template argument list. @@ -575,18 +569,18 @@ static void clearLinkageForClass(const CXXRecordDecl *record) { i = record->decls_begin(), e = record->decls_end(); i != e; ++i) { Decl *child = *i; if (isa<NamedDecl>(child)) - cast<NamedDecl>(child)->ClearLVCache(); + cast<NamedDecl>(child)->ClearLinkageCache(); } } void NamedDecl::anchor() { } -void NamedDecl::ClearLVCache() { +void NamedDecl::ClearLinkageCache() { // Note that we can't skip clearing the linkage of children just // because the parent doesn't have cached linkage: we don't cache // when computing linkage for parent contexts. - CacheValidAndVisibility = 0; + HasCachedLinkage = 0; // If we're changing the linkage of a class, we need to reset the // linkage of child declarations, too. @@ -597,44 +591,44 @@ void NamedDecl::ClearLVCache() { dyn_cast<ClassTemplateDecl>(const_cast<NamedDecl*>(this))) { // Clear linkage for the template pattern. CXXRecordDecl *record = temp->getTemplatedDecl(); - record->CacheValidAndVisibility = 0; + record->HasCachedLinkage = 0; clearLinkageForClass(record); // We need to clear linkage for specializations, too. for (ClassTemplateDecl::spec_iterator i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i) - i->ClearLVCache(); + i->ClearLinkageCache(); } // Clear cached linkage for function template decls, too. if (FunctionTemplateDecl *temp = dyn_cast<FunctionTemplateDecl>(const_cast<NamedDecl*>(this))) { - temp->getTemplatedDecl()->ClearLVCache(); + temp->getTemplatedDecl()->ClearLinkageCache(); for (FunctionTemplateDecl::spec_iterator i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i) - i->ClearLVCache(); + i->ClearLinkageCache(); } } Linkage NamedDecl::getLinkage() const { - return getLinkageAndVisibility().linkage(); + if (HasCachedLinkage) { + assert(Linkage(CachedLinkage) == + getLVForDecl(this, true).linkage()); + return Linkage(CachedLinkage); + } + + CachedLinkage = getLVForDecl(this, true).linkage(); + HasCachedLinkage = 1; + return Linkage(CachedLinkage); } LinkageInfo NamedDecl::getLinkageAndVisibility() const { - if (CacheValidAndVisibility) { - Linkage L = static_cast<Linkage>(CachedLinkage); - Visibility V = static_cast<Visibility>(CacheValidAndVisibility - 1); - bool Explicit = CachedVisibilityExplicit; - LinkageInfo LV(L, V, Explicit); - assert(LV == computeLVForDecl(this, false)); - return LV; - } - LinkageInfo LV = computeLVForDecl(this, false); - CachedLinkage = LV.linkage(); - CacheValidAndVisibility = LV.visibility() + 1; - CachedVisibilityExplicit = LV.visibilityExplicit(); - return LV; + LinkageInfo LI = getLVForDecl(this, false); + assert(!HasCachedLinkage || Linkage(CachedLinkage) == LI.linkage()); + HasCachedLinkage = 1; + CachedLinkage = LI.linkage(); + return LI; } llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const { @@ -698,7 +692,7 @@ llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const { return llvm::Optional<Visibility>(); } -static LinkageInfo computeLVForDecl(const NamedDecl *D, bool OnlyTemplate) { +static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) { // Objective-C: treat all Objective-C declarations as having external // linkage. switch (D->getKind()) { @@ -1163,7 +1157,7 @@ VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { void VarDecl::setStorageClass(StorageClass SC) { assert(isLegalForVariable(SC)); if (getStorageClass() != SC) - ClearLVCache(); + ClearLinkageCache(); VarDeclBits.SClass = SC; } @@ -1659,7 +1653,6 @@ void FunctionDecl::setBody(Stmt *B) { Body = B; if (B) EndRangeLoc = B->getLocEnd(); - ClearLVCache(); } void FunctionDecl::setPure(bool P) { @@ -1764,7 +1757,7 @@ FunctionDecl *FunctionDecl::getCanonicalDecl() { void FunctionDecl::setStorageClass(StorageClass SC) { assert(isLegalForFunction(SC)); if (getStorageClass() != SC) - ClearLVCache(); + ClearLinkageCache(); SClass = SC; } @@ -2534,8 +2527,8 @@ TagDecl* TagDecl::getCanonicalDecl() { void TagDecl::setTypedefNameForAnonDecl(TypedefNameDecl *TDD) { TypedefNameDeclOrQualifier = TDD; if (TypeForDecl) - const_cast<Type*>(TypeForDecl)->ClearLVCache(); - ClearLVCache(); + const_cast<Type*>(TypeForDecl)->ClearLinkageCache(); + ClearLinkageCache(); } void TagDecl::startDefinition() { |