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

            Bug ID: 61982
           Summary: Optimizer does not eliminate stores to destroyed
                    objects
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: a...@cloudius-systems.com

After a destructor is run, access to the object is forbidden; the object is
turned into a pile of bytes.  Yet the generated code for:


struct X { 
  int i; 
  void clear() { i = 0; } 
}; 

void f(X* x) { 
  x->clear(); 
  x->~X(); 
} 

void g(X* x) {
  x->clear();
  delete x;
}

contains a store for each of f() and g(), stores that should have been
eliminated:

0000000000000000 <f(X*)>:
   0:    c7 07 00 00 00 00        movl   $0x0,(%rdi)
   6:    c3                       retq   
   7:    66 0f 1f 84 00 00 00     nopw   0x0(%rax,%rax,1)
   e:    00 00 

0000000000000010 <g(X*)>:
  10:    c7 07 00 00 00 00        movl   $0x0,(%rdi)
  16:    e9 00 00 00 00           jmpq   1b <g(X*)+0xb>
            17: R_X86_64_PC32    operator delete(void*)-0x4


To be clear, the generated code is correct, but not optimal.

Reply via email to