[llvm-commits] [llvm] r81736 - /llvm/trunk/lib/VMCore/Verifier.cpp

Nick Lewycky nicholas at mxc.ca
Sun Sep 13 17:36:52 PDT 2009


Author: nicholas
Date: Sun Sep 13 19:36:52 2009
New Revision: 81736

URL: http://llvm.org/viewvc/llvm-project?rev=81736&view=rev
Log:
Don't leak! Always remove oneself as a listener after adding oneself.

Modified:
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=81736&r1=81735&r2=81736&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Sun Sep 13 19:36:52 2009
@@ -57,7 +57,7 @@
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/InstVisitor.h"
-#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
@@ -108,25 +108,34 @@
 
 namespace {
   struct TypeSet : public AbstractTypeUser {
-    SmallSet<const Type *, 16> Types;
+    SmallSetVector<const Type *, 16> Types;
 
     /// Insert a type into the set of types.
     bool insert(const Type *Ty) {
-      bool Inserted = Types.insert(Ty);
-      if (!Inserted)
+      if (!Types.insert(Ty))
         return false;
-
       if (Ty->isAbstract())
         Ty->addAbstractTypeUser(this);
       return true;
     }
 
+    // Remove ourselves as abstract type listeners for any types that remain
+    // abstract when the TypeSet is destroyed.
+    ~TypeSet() {
+      for (SmallSetVector<const Type *, 16>::iterator I = Types.begin(),
+             E = Types.end(); I != E; ++I) {
+        const Type *Ty = *I;
+        if (Ty->isAbstract())
+          Ty->removeAbstractTypeUser(this);
+      }
+    }
+
     // Abstract type user interface.
 
     /// Remove types from the set when refined. Do not insert the type it was
     /// refined to because that type hasn't been verified yet.
     void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
-      Types.erase(OldTy);
+      Types.remove(OldTy);
       OldTy->removeAbstractTypeUser(this);
     }
     void typeBecameConcrete(const DerivedType *AbsTy) {}





More information about the llvm-commits mailing list