From f76b092e1a6f0df4a5c64aae3c71d6e81e4b717c Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 8 Feb 2011 19:01:05 +0000 Subject: [PATCH] Clear the linkage cache recursively. Fixes PR8926. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125104 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 2 +- lib/AST/Decl.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index f81f9d0ca4..e8431c1106 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -274,7 +274,7 @@ public: /// \brief Clear the linkage cache in response to a change /// to the declaration. - void ClearLinkageCache() { HasCachedLinkage = 0; } + void ClearLinkageCache(); /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for /// the underlying named decl. diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 4fb47bfcdc..11614df500 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -579,6 +579,37 @@ static LinkageInfo getLVForClassMember(const NamedDecl *D, LVFlags F) { return LV; } +static void clearLinkageForClass(const CXXRecordDecl *record) { + for (CXXRecordDecl::decl_iterator + i = record->decls_begin(), e = record->decls_end(); i != e; ++i) { + Decl *child = *i; + if (isa(child)) + cast(child)->ClearLinkageCache(); + } +} + +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. + + HasCachedLinkage = 0; + + // If we're changing the linkage of a class, we need to reset the + // linkage of child declarations, too. + if (const CXXRecordDecl *record = dyn_cast(this)) + clearLinkageForClass(record); + + if (const ClassTemplateDecl *temp = dyn_cast(this)) { + // Clear linkage for the template pattern. + CXXRecordDecl *record = temp->getTemplatedDecl(); + record->HasCachedLinkage = 0; + clearLinkageForClass(record); + + // ...do we need to clear linkage for specializations, too? + } +} + Linkage NamedDecl::getLinkage() const { if (HasCachedLinkage) { assert(Linkage(CachedLinkage) == -- 2.50.1