[cfe-commits] r66020 - in /cfe/trunk: include/clang/AST/Attr.h lib/AST/DeclBase.cpp lib/Sema/SemaDecl.cpp

Chris Lattner sabre at nondot.org
Tue Mar 3 22:05:19 PST 2009


Author: lattner
Date: Wed Mar  4 00:05:19 2009
New Revision: 66020

URL: http://llvm.org/viewvc/llvm-project?rev=66020&view=rev
Log:
add an a Attr::Destroy method and force clients to go through it.  As part of 
this, make DeclBase::Destroy destroy attributes instead of the DeclBase dtor.

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=66020&r1=66019&r2=66020&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Wed Mar  4 00:05:19 2009
@@ -20,6 +20,7 @@
 #include <algorithm>
 
 namespace clang {
+  class ASTContext;
 
 /// Attr - This represents one attribute.
 class Attr {
@@ -69,10 +70,14 @@
 
 protected:
   Attr(Kind AK) : Next(0), AttrKind(AK), Inherited(false) {}
-public:
   virtual ~Attr() {
     delete Next;
   }
+public:
+  
+  void Destroy(ASTContext &C) {
+    delete this;
+  }
 
   /// \brief Whether this attribute should be merged to new
   /// declarations.

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=66020&r1=66019&r2=66020&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Mar  4 00:05:19 2009
@@ -121,15 +121,7 @@
   if (isOutOfSemaDC())
     delete getMultipleDC();
 
-  if (!HasAttrs)
-    return;
-  
-  DeclAttrMapTy::iterator it = DeclAttrs->find(this);
-  assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
-
-  // release attributes.
-  delete it->second;
-  invalidateAttrs();
+  assert(!HasAttrs && "attributes should have been freed by Destroy");
 }
 
 void Decl::addAttr(Attr *NewAttr) {
@@ -189,7 +181,18 @@
 }
 
 
-void Decl::Destroy(ASTContext& C) {
+void Decl::Destroy(ASTContext &C) {
+  // Free attributes for this decl.
+  if (HasAttrs) {
+    DeclAttrMapTy::iterator it = DeclAttrs->find(this);
+    assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
+  
+    // release attributes.
+    it->second->Destroy(C);
+    invalidateAttrs();
+    HasAttrs = false;
+  }
+  
 #if 0
   // FIXME: Once ownership is fully understood, we can enable this code
   if (DeclContext *DC = dyn_cast<DeclContext>(this))

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66020&r1=66019&r2=66020&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar  4 00:05:19 2009
@@ -482,11 +482,11 @@
 }
 
 /// MergeAttributes - append attributes from the Old decl to the New one.
-static void MergeAttributes(Decl *New, Decl *Old) {
-  Attr *attr = const_cast<Attr*>(Old->getAttrs()), *tmp;
+static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) {
+  Attr *attr = const_cast<Attr*>(Old->getAttrs());
 
   while (attr) {
-    tmp = attr;
+    Attr *tmp = attr;
     attr = attr->getNext();
 
     if (!DeclHasAttr(New, tmp) && tmp->isMerged()) {
@@ -494,7 +494,7 @@
       New->addAttr(tmp);
     } else {
       tmp->setNext(0);
-      delete(tmp);
+      tmp->Destroy(C);
     }
   }
 
@@ -678,7 +678,7 @@
 /// \returns false
 bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) {
   // Merge the attributes
-  MergeAttributes(New, Old);
+  MergeAttributes(New, Old, Context);
 
   // Merge the storage class.
   New->setStorageClass(Old->getStorageClass());
@@ -767,7 +767,7 @@
     return true;
   }
 
-  MergeAttributes(New, Old);
+  MergeAttributes(New, Old, Context);
 
   // Merge the types
   QualType MergedT = Context.mergeTypes(New->getType(), Old->getType());





More information about the cfe-commits mailing list