public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "arnej at pvv dot ntnu.no" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught Date: Sun, 22 May 2011 20:10:00 -0000 [thread overview] Message-ID: <bug-49115-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115 Summary: invalid return value optimization (?) when exception is thrown and caught Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: arnej@pvv.ntnu.no we have some code that started failing when I tried upgrading our tool chain to GCC 4.5.2; it gets stale data in an object when an exception is thrown during assignment. It looks to me like return value optimization will cause the object constructor to be optimized away, but I'm not totally certain if that is the actual problem, nor what the C++ language guarantees in this situation. A self-contained test program is below, failing for me on x86_64 using: GNU C++ (GCC) version 4.5.2 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 3.0.1, MPC version 0.9 ----- test program follows ----- extern "C" { extern long write(int, const void *, unsigned long); } struct MyException {}; int simfail = 7; struct Data { int nr; Data() : nr(66) {} }; Data getData(int i) { if (simfail == i) throw MyException(); Data data; data.nr = i; return data; } bool verify() { char bad[7] = "BAD x\n"; for (int i = 0; i < 10; i++) { Data data; try { data = getData(i); } catch (MyException& e) { if (data.nr != 66) { bad[4] = '0' + data.nr; write(2, bad, 6); return false; } } } return true; } int main(int, char **) { simfail = 4; return verify() ? 0 : 1; }
next reply other threads:[~2011-05-22 20:05 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-05-22 20:10 arnej at pvv dot ntnu.no [this message] 2011-05-22 20:56 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org 2011-05-23 12:37 ` [Bug tree-optimization/49115] [4.5/4.6 Regression] " rguenth at gcc dot gnu.org 2011-05-23 13:00 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org 2011-06-12 13:44 ` [Bug tree-optimization/49115] [4.5/4.6 Regression] " rguenth at gcc dot gnu.org 2011-06-17 11:27 ` rguenth at gcc dot gnu.org 2011-07-04 13:25 ` [Bug tree-optimization/49115] [4.5 " rguenth at gcc dot gnu.org 2011-07-04 13:26 ` rguenth at gcc dot gnu.org
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-49115-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: linkBe 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).