llvm.org GIT mirror llvm / 1cefd7c
Catch more cases of a pointer being marked garbage twice. This helps when debugging some leaks (PR5770 in particular). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91713 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 9 years ago
2 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4545 // immediately, it is added to the CachedValue Value. If it is
4646 // immediately removed, no set search need be performed.
4747 void addGarbage(const T* o) {
48 assert(Ts.count(o) == 0 && "Object already in set!");
4849 if (Cache) {
49 assert(Ts.count(Cache) == 0 && "Object already in set!");
50 assert(Cache != o && "Object already in set!");
5051 Ts.insert(Cache);
5152 }
5253 Cache = o;
0 //===- llvm/unittest/LeakDetector/LeakDetector.cpp - LeakDetector tests ---===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10 #include "llvm/Support/LeakDetector.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 #ifdef GTEST_HAS_DEATH_TEST
17 TEST(LeakDetector, Death1) {
18 LeakDetector::addGarbageObject((void*) 1);
19 LeakDetector::addGarbageObject((void*) 2);
20
21 EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 1),
22 ".*Ts.count\\(o\\) == 0 && \"Object already in set!\"");
23 EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 2),
24 "Cache != o && \"Object already in set!\"");
25 }
26 #endif
27
28 }