diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2015-08-01 19:46:34 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2015-08-02 16:53:24 -0700 |
commit | 53833298f3822b2b8b78c9dc85160d65d78a6857 (patch) | |
tree | 569639ac7d0d9419534118f8cf881ded83a1ddc6 | |
parent | 024bae96ce8e1591993fc0da191ce0a92d609481 (diff) | |
download | gperftools-53833298f3822b2b8b78c9dc85160d65d78a6857.tar.gz |
unbreak heap_checker_unittest on gcc 5
GCC 5 ended up too smart and optimized out assignment of allocated
block to global variable. Which caused test to fail since it triggered
unexpected "leak".
-rw-r--r-- | src/tests/heap-checker_unittest.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/tests/heap-checker_unittest.cc b/src/tests/heap-checker_unittest.cc index 13cbb86..8c8f865 100644 --- a/src/tests/heap-checker_unittest.cc +++ b/src/tests/heap-checker_unittest.cc @@ -1241,12 +1241,24 @@ REGISTER_OBJ_MAKER(nesting_i1, Nesting::Inner* p = &((new Nesting())->i1);) REGISTER_OBJ_MAKER(nesting_i2, Nesting::Inner* p = &((new Nesting())->i2);) REGISTER_OBJ_MAKER(nesting_i3, Nesting::Inner* p = &((new Nesting())->i3);) +void (* volatile init_forcer)(...); + // allocate many objects reachable from global data static void TestHeapLeakCheckerLiveness() { live_leak_mutable.ptr = new(initialized) char[77]; live_leak_templ_mutable.ptr = new(initialized) Array<char>(); live_leak_templ_mutable.val = Array<char>(); + // smart compiler may see that live_leak_mutable is not used + // anywhere so .ptr assignment is not used. + // + // We force compiler to assume that it is used by having function + // variable (set to 0 which hopefully won't be known to compiler) + // which gets address of those objects. So compiler has to assume + // that .ptr is used. + if (init_forcer) { + init_forcer(&live_leak_mutable, &live_leak_templ_mutable); + } TestObjMakers(); } |