public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "avi@cloudius-systems.com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-61982-4@http.gcc.gnu.org/bugzilla/> (raw)

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 <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	other threads:[~2014-07-31 18:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31 18:54 avi@cloudius-systems.com [this message]
2014-08-01  8:24 ` [Bug c++/61982] " rguenth at gcc dot gnu.org
2014-08-01 15:12 ` jakub at gcc dot gnu.org
2014-08-01 16:32 ` avi@cloudius-systems.com
2014-08-01 16:52 ` glisse at gcc dot gnu.org
2014-08-01 17:10 ` avi@cloudius-systems.com
2014-08-01 18:10 ` daniel.kruegler at googlemail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61982-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).