Catch more cases of a pointer being marked garbage twice. This helps when
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2009 20:35:38 +0000 (20:35 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2009 20:35:38 +0000 (20:35 +0000)
debugging some leaks (PR5770 in particular).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91713 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/LeaksContext.h
unittests/Support/LeakDetectorTest.cpp [new file with mode: 0644]

index bd10a479ae2a0804c0d3c049eaa6f241474adbed..abff090b87963ff4701cd50863b73d9f3db5b054 100644 (file)
@@ -46,8 +46,9 @@ struct LeakDetectorImpl {
   // 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;
diff --git a/unittests/Support/LeakDetectorTest.cpp b/unittests/Support/LeakDetectorTest.cpp
new file mode 100644 (file)
index 0000000..85ef046
--- /dev/null
@@ -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
+
+}