public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught
@ 2011-05-22 20:10 arnej at pvv dot ntnu.no
2011-05-22 20:56 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: arnej at pvv dot ntnu.no @ 2011-05-22 20:10 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
@ 2011-05-22 20:56 ` 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
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-22 20:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2011.05.22 20:33:26
Component|c++ |tree-optimization
AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
Known to fail| |4.7.0
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-22 20:33:26 UTC ---
Confirmed. Reduced testcase:
extern "C" void abort (void);
struct MyException {};
struct Data {
int nr;
Data() : nr(66) {}
};
Data __attribute__((noinline,noclone)) getData(int i)
{
if (i) throw MyException();
Data data;
data.nr = i;
return data;
}
int main(int, char **)
{
Data data;
try {
data = getData(1);
} catch (MyException& e) {
if (data.nr != 66)
abort ();
}
}
what happens is that the store to data.nr from the constructor call in
main is DCEd. Looks like an alias issue to me. Mine.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] [4.5/4.6 Regression] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
2011-05-22 20:56 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org
@ 2011-05-23 12:37 ` rguenth at gcc dot gnu.org
2011-05-23 13:00 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-23 12:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.4.5, 4.7.0
Target Milestone|--- |4.5.4
Summary|invalid return value |[4.5/4.6 Regression]
|optimization (?) when |invalid return value
|exception is thrown and |optimization (?) when
|caught |exception is thrown and
| |caught
Known to fail|4.7.0 |4.5.3, 4.6.0
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-23 12:11:14 UTC ---
Fixed on trunk sofar. Works with 4.4.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
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 ` 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
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-23 13:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-23 12:08:45 UTC ---
Author: rguenth
Date: Mon May 23 12:08:41 2011
New Revision: 174066
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174066
Log:
2011-05-23 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49115
* tree-ssa-alias.c (stmt_kills_ref_p_1): If the assignment
is not necessarily carried out, do not claim it kills the ref.
* tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.
* g++.dg/torture/pr49115.C: New testcase.
Added:
trunk/gcc/testsuite/g++.dg/torture/pr49115.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-alias.c
trunk/gcc/tree-ssa-dce.c
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] [4.5/4.6 Regression] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
` (2 preceding siblings ...)
2011-05-23 13:00 ` [Bug tree-optimization/49115] " rguenth at gcc dot gnu.org
@ 2011-06-12 13:44 ` rguenth at gcc dot gnu.org
2011-06-17 11:27 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-12 13:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] [4.5/4.6 Regression] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
` (3 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-17 11:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-17 11:27:41 UTC ---
Author: rguenth
Date: Fri Jun 17 11:27:37 2011
New Revision: 175148
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175148
Log:
2011-06-17 Richard Guenther <rguenther@suse.de>
Backport from mainline
2011-05-23 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49115
* tree-ssa-alias.c (stmt_kills_ref_p_1): If the assignment
is not necessarily carried out, do not claim it kills the ref.
* tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.
* g++.dg/torture/pr49115.C: New testcase.
Added:
branches/gcc-4_6-branch/gcc/testsuite/g++.dg/torture/pr49115.C
Modified:
branches/gcc-4_6-branch/gcc/ChangeLog
branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
branches/gcc-4_6-branch/gcc/tree-ssa-alias.c
branches/gcc-4_6-branch/gcc/tree-ssa-dce.c
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] [4.5 Regression] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
` (4 preceding siblings ...)
2011-06-17 11:27 ` rguenth at gcc dot gnu.org
@ 2011-07-04 13:25 ` rguenth at gcc dot gnu.org
2011-07-04 13:26 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-04 13:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-04 13:25:39 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49115] [4.5 Regression] invalid return value optimization (?) when exception is thrown and caught
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
` (5 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-04 13:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49115
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-04 13:25:24 UTC ---
Author: rguenth
Date: Mon Jul 4 13:25:21 2011
New Revision: 175812
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175812
Log:
2011-07-04 Richard Guenther <rguenther@suse.de>
Backport from mainline
2011-05-23 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49115
* tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.
* g++.dg/torture/pr49115.C: New testcase.
Added:
branches/gcc-4_5-branch/gcc/testsuite/g++.dg/torture/pr49115.C
Modified:
branches/gcc-4_5-branch/gcc/ChangeLog
branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
branches/gcc-4_5-branch/gcc/tree-ssa-dce.c
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-07-04 13:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-22 20:10 [Bug c++/49115] New: invalid return value optimization (?) when exception is thrown and caught arnej at pvv dot ntnu.no
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
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).