From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9802 invoked by alias); 31 Jul 2014 18:54:18 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 9770 invoked by uid 48); 31 Jul 2014 18:54:15 -0000 From: "avi@cloudius-systems.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/61982] New: Optimizer does not eliminate stores to destroyed objects Date: Thu, 31 Jul 2014 18:54:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: avi@cloudius-systems.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg02082.txt.bz2 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: avi@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 : 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 : 10: c7 07 00 00 00 00 movl $0x0,(%rdi) 16: e9 00 00 00 00 jmpq 1b 17: R_X86_64_PC32 operator delete(void*)-0x4 To be clear, the generated code is correct, but not optimal.