From: NAKAMURA Takumi Date: Tue, 25 Dec 2012 04:47:44 +0000 (+0000) Subject: Revert r171048, "Cache visibility of decls." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eaf5ec43ec52f650a00254d1c20d51fb7671aead;p=clang 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 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index bb75895df5..e00779844c 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -228,12 +228,6 @@ public: "Enum truncated!"); } - bool operator==(const LinkageInfo &Other) { - return linkage_ == Other.linkage_ && - visibility_ == Other.visibility_ && - explicit_ == Other.explicit_; - } - static LinkageInfo external() { return LinkageInfo(); } @@ -329,7 +323,7 @@ public: /// \brief Clear the linkage cache in response to a change /// to the declaration. - void ClearLVCache(); + void ClearLinkageCache(); /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for /// the underlying named decl. @@ -3325,7 +3319,7 @@ void Redeclarable::setPreviousDeclaration(decl_type *PrevDecl) { // First one will point to this one as latest. First->RedeclLink = LatestDeclLink(static_cast(this)); if (NamedDecl *ND = dyn_cast(static_cast(this))) - ND->ClearLVCache(); + ND->ClearLinkageCache(); } // Inline function definitions. diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 823340aeaf..e3fa41ef31 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -241,7 +241,7 @@ private: SourceLocation Loc; /// DeclKind - This indicates which class this is. - unsigned DeclKind : 6; + unsigned DeclKind : 8; /// InvalidDecl - This indicates a semantic error occurred. unsigned InvalidDecl : 1; @@ -283,16 +283,15 @@ protected: /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. unsigned IdentifierNamespace : 12; - /// These fields are only valid for NamedDecls subclasses. + /// \brief Whether the \c CachedLinkage field is active. + /// + /// This field is only valid for NamedDecls subclasses. + mutable unsigned HasCachedLinkage : 1; + + /// \brief If \c HasCachedLinkage, the linkage of this declaration. /// - /// \brief Nonzero if the cache (i.e. the bitfields here starting - /// with 'Cache') is valid. If so, then this is a - /// LangOptions::VisibilityMode+1. - mutable unsigned CacheValidAndVisibility : 2; - /// \brief the linkage of this declaration. + /// This field is only valid for NamedDecls subclasses. mutable unsigned CachedLinkage : 2; - /// \brief true if the visibility is explicit. - mutable unsigned CachedVisibilityExplicit : 1; friend class ASTDeclWriter; friend class ASTDeclReader; @@ -309,7 +308,7 @@ protected: HasAttrs(false), Implicit(false), Used(false), Referenced(false), Access(AS_none), FromASTFile(0), Hidden(0), IdentifierNamespace(getIdentifierNamespaceForKind(DK)), - CacheValidAndVisibility(0) + HasCachedLinkage(0) { if (StatisticsEnabled) add(DK); } @@ -319,7 +318,7 @@ protected: HasAttrs(false), Implicit(false), Used(false), Referenced(false), Access(AS_none), FromASTFile(0), Hidden(0), IdentifierNamespace(getIdentifierNamespaceForKind(DK)), - CacheValidAndVisibility(0) + HasCachedLinkage(0) { if (StatisticsEnabled) add(DK); } diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 7277f0fc68..cf3b565fc3 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1786,7 +1786,7 @@ public: std::pair getLinkageAndVisibility() const; /// \brief Note that the linkage is no longer known. - void ClearLVCache(); + void ClearLinkageCache(); const char *getTypeClassName() const; 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(child)) - cast(child)->ClearLVCache(); + cast(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(const_cast(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(const_cast(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(CachedLinkage); - Visibility V = static_cast(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 NamedDecl::getExplicitVisibility() const { @@ -698,7 +692,7 @@ llvm::Optional NamedDecl::getExplicitVisibility() const { return llvm::Optional(); } -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(TypeForDecl)->ClearLVCache(); - ClearLVCache(); + const_cast(TypeForDecl)->ClearLinkageCache(); + ClearLinkageCache(); } void TagDecl::startDefinition() { diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 673528ada0..26eee2d74a 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -2186,7 +2186,7 @@ std::pair Type::getLinkageAndVisibility() const { return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility()); } -void Type::ClearLVCache() { +void Type::ClearLinkageCache() { TypeBits.CacheValidAndVisibility = 0; if (QualType(this, 0) != CanonicalType) CanonicalType->TypeBits.CacheValidAndVisibility = 0; diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index 3bfb8f22b4..4406f2d956 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -309,8 +309,7 @@ void Sema::AddPushedVisibilityAttribute(Decl *D) { if (!VisContext) return; - NamedDecl *ND = dyn_cast(D); - if (ND && ND->getExplicitVisibility()) + if (isa(D) && cast(D)->getExplicitVisibility()) return; VisStack *Stack = static_cast(VisContext); @@ -321,7 +320,6 @@ void Sema::AddPushedVisibilityAttribute(Decl *D) { = (VisibilityAttr::VisibilityType) rawType; SourceLocation loc = Stack->back().second; - ND->ClearLVCache(); D->addAttr(::new (Context) VisibilityAttr(loc, Context, type)); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e1d772b084..105ef49bd8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1775,13 +1775,9 @@ bool Sema::mergeDeclAttribute(Decl *D, InheritableAttr *Attr) { AA->getIntroduced(), AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(), AA->getMessage()); - else if (VisibilityAttr *VA = dyn_cast(Attr)) { + else if (VisibilityAttr *VA = dyn_cast(Attr)) NewAttr = mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility()); - if (NewAttr) { - NamedDecl *ND = cast(D); - ND->ClearLVCache(); - } - } else if (DLLImportAttr *ImportA = dyn_cast(Attr)) + else if (DLLImportAttr *ImportA = dyn_cast(Attr)) NewAttr = mergeDLLImportAttr(D, ImportA->getRange()); else if (DLLExportAttr *ExportA = dyn_cast(Attr)) NewAttr = mergeDLLExportAttr(D, ExportA->getRange()); @@ -6615,7 +6611,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, } VDecl->setTypeSourceInfo(DeducedType); VDecl->setType(DeducedType->getType()); - VDecl->ClearLVCache(); + VDecl->ClearLinkageCache(); // In ARC, infer lifetime. if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl)) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 437e2a826b..22aad165e9 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2147,11 +2147,8 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, Deprecated.Version, Obsoleted.Version, IsUnavailable, Str); - if (NewAttr) { + if (NewAttr) D->addAttr(NewAttr); - NamedDecl *ND = cast(D); - ND->ClearLVCache(); - } } VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range, @@ -2168,8 +2165,6 @@ VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range, Diag(ExistingAttr->getLocation(), diag::err_mismatched_visibility); Diag(Range.getBegin(), diag::note_previous_attribute); D->dropAttr(); - NamedDecl *ND = cast(D); - ND->ClearLVCache(); } return ::new (Context) VisibilityAttr(Range, Context, Vis); } @@ -2213,11 +2208,8 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) { } VisibilityAttr *NewAttr = S.mergeVisibilityAttr(D, Attr.getRange(), type); - if (NewAttr) { + if (NewAttr) D->addAttr(NewAttr); - NamedDecl *ND = cast(D); - ND->ClearLVCache(); - } } static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,