[Bug middle-end/89303] [8 Regression] memory leak with shared_ptr and enable_shared_from_this

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 13 10:47:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89303

--- Comment #18 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Before fre3 we have:
  _24 = malloc (40);
...
  MEM[(struct __allocated_ptr *)&__guard clique 9 base 1]._M_ptr = _24;
  _15 = __guard._M_ptr;
...
  _16 = &MEM[(struct __aligned_buffer *)_15 + 16B]._M_storage;
...
  MEM[(struct __weak_count *)_15 + 24B clique 8 base 1]._M_pi = 0B;
...
  MEM[(struct __shared_count *)this_6(D) + 8B clique 2 base 1]._M_pi = _15;
  MEM[(struct blob * &)this_6(D) clique 2 base 0] = _16;
...
  _3 = MEM[(struct __shared_ptr *)this_6(D) clique 1 base 1]._M_ptr;
...
  __tmp_25 = MEM[(const struct __shared_count &)this_6(D) + 8 clique 10 base
1]._M_pi;
...
  MEM[(struct __weak_count *)_3 + 8B clique 10 base 0]._M_pi = __tmp_25;
fre3 makes:
  _24 = malloc (40);
...
  _16 = &MEM[(struct __aligned_buffer *)_24 + 16B]._M_storage;
...
  MEM[(struct __weak_count *)_24 + 24B clique 8 base 1]._M_pi = 0B;
...
  MEM[(struct __shared_count *)this_6(D) + 8B clique 2 base 1]._M_pi = _24;
  MEM[(struct blob * &)this_6(D) clique 2 base 0] = _16;
...
  _19 = MEM[(struct __weak_count *)_24 + 24B clique 6 base 1]._M_pi;
...
  MEM[(struct __weak_count *)_16 + 8B clique 10 base 0]._M_pi = _24;
out of this and finally dce2 deletes that last store:
Eliminating unnecessary statements:
Deleting : MEM[(struct __weak_count *)_16 + 8B]._M_pi = _24;

With -O1 -fno-tree-dce -fno-tree-dse there are no leaks.


More information about the Gcc-bugs mailing list