[llvm-commits] [llvm] r91713 - in /llvm/trunk: lib/VMCore/LeaksContext.h unittests/Support/LeakDetectorTest.cpp

Rafael Espindola rafael.espindola at gmail.com
Fri Dec 18 12:35:39 PST 2009


Author: rafael
Date: Fri Dec 18 14:35:38 2009
New Revision: 91713

URL: http://llvm.org/viewvc/llvm-project?rev=91713&view=rev
Log:
Catch more cases of a pointer being marked garbage twice. This helps when
debugging some leaks (PR5770 in particular).


Added:
    llvm/trunk/unittests/Support/LeakDetectorTest.cpp
Modified:
    llvm/trunk/lib/VMCore/LeaksContext.h

Modified: llvm/trunk/lib/VMCore/LeaksContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LeaksContext.h?rev=91713&r1=91712&r2=91713&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LeaksContext.h (original)
+++ llvm/trunk/lib/VMCore/LeaksContext.h Fri Dec 18 14:35:38 2009
@@ -46,8 +46,9 @@
   // immediately, it is added to the CachedValue Value.  If it is
   // immediately removed, no set search need be performed.
   void addGarbage(const T* o) {
+    assert(Ts.count(o) == 0 && "Object already in set!");
     if (Cache) {
-      assert(Ts.count(Cache) == 0 && "Object already in set!");
+      assert(Cache != o && "Object already in set!");
       Ts.insert(Cache);
     }
     Cache = o;

Added: llvm/trunk/unittests/Support/LeakDetectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/LeakDetectorTest.cpp?rev=91713&view=auto

==============================================================================
--- llvm/trunk/unittests/Support/LeakDetectorTest.cpp (added)
+++ llvm/trunk/unittests/Support/LeakDetectorTest.cpp Fri Dec 18 14:35:38 2009
@@ -0,0 +1,29 @@
+//===- llvm/unittest/LeakDetector/LeakDetector.cpp - LeakDetector tests ---===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/Support/LeakDetector.h"
+
+using namespace llvm;
+
+namespace {
+
+#ifdef GTEST_HAS_DEATH_TEST
+TEST(LeakDetector, Death1) {
+  LeakDetector::addGarbageObject((void*) 1);
+  LeakDetector::addGarbageObject((void*) 2);
+
+  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 1),
+               ".*Ts.count\\(o\\) == 0 && \"Object already in set!\"");
+  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 2),
+               "Cache != o && \"Object already in set!\"");
+}
+#endif
+
+}





More information about the llvm-commits mailing list