[cfe-commits] r125104 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp

John McCall rjmccall at apple.com
Tue Feb 8 11:01:05 PST 2011


Author: rjmccall
Date: Tue Feb  8 13:01:05 2011
New Revision: 125104

URL: http://llvm.org/viewvc/llvm-project?rev=125104&view=rev
Log:
Clear the linkage cache recursively.  Fixes PR8926.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=125104&r1=125103&r2=125104&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Feb  8 13:01:05 2011
@@ -274,7 +274,7 @@
 
   /// \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.

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=125104&r1=125103&r2=125104&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Feb  8 13:01:05 2011
@@ -579,6 +579,37 @@
   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<NamedDecl>(child))
+      cast<NamedDecl>(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<CXXRecordDecl>(this))
+    clearLinkageForClass(record);
+
+  if (const ClassTemplateDecl *temp = dyn_cast<ClassTemplateDecl>(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) ==





More information about the cfe-commits mailing list