public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address @ 2011-11-30 9:14 nkeynes at deadcoderemoval dot net 2011-12-14 23:29 ` [Bug rtl-optimization/51353] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: nkeynes at deadcoderemoval dot net @ 2011-11-30 9:14 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51353 Bug #: 51353 Summary: GCC incorrectly optimizes away assignment to return address Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: nkeynes@deadcoderemoval.net In the following code, GCC with -O completely removes the if block and assignment: int foo( int arg, void *exc ) { if( arg < 2 ) { *(((void **)__builtin_frame_address(0))+1) = exc; } return 0; } Producing (for i386): .globl _foo _foo: pushl %ebp movl %esp, %ebp movl $0, %eax popl %ebp ret The relative merits and portability of the code aside, it doesn't seem correct to completely remove the assignment. The code was compiled correctly with gcc 4.2.4, and fails with 4.4.6, 4.5.3, and 4.6.1. The generated code is also correct with all optimizations off when compiled with any of these versions. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/51353] GCC incorrectly optimizes away assignment to return address 2011-11-30 9:14 [Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address nkeynes at deadcoderemoval dot net @ 2011-12-14 23:29 ` pinskia at gcc dot gnu.org 2011-12-15 2:16 ` nkeynes at deadcoderemoval dot net 2012-01-04 0:38 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2011-12-14 23:29 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51353 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-12-14 23:28:00 UTC --- I think this should be: *(((volatile void **)__builtin_frame_address(0))+1) = exc; GCC thinks it does not alias thing which is why it is removing it. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/51353] GCC incorrectly optimizes away assignment to return address 2011-11-30 9:14 [Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address nkeynes at deadcoderemoval dot net 2011-12-14 23:29 ` [Bug rtl-optimization/51353] " pinskia at gcc dot gnu.org @ 2011-12-15 2:16 ` nkeynes at deadcoderemoval dot net 2012-01-04 0:38 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: nkeynes at deadcoderemoval dot net @ 2011-12-15 2:16 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51353 --- Comment #2 from Nathan Keynes <nkeynes at deadcoderemoval dot net> 2011-12-15 02:14:48 UTC --- Testing this out, *(((volatile void **)__builtin_frame_address(0))+1) = exc; still does not work in 4.4.6 and 4.5.3, but *(((void * volatile *)__builtin_frame_address(0))+1) = exc; does work correctly. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/51353] GCC incorrectly optimizes away assignment to return address 2011-11-30 9:14 [Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address nkeynes at deadcoderemoval dot net 2011-12-14 23:29 ` [Bug rtl-optimization/51353] " pinskia at gcc dot gnu.org 2011-12-15 2:16 ` nkeynes at deadcoderemoval dot net @ 2012-01-04 0:38 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2012-01-04 0:38 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51353 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-04 00:37:33 UTC --- __builtin_frame_address(0) points to an address on the stack which means at the end of the function, it can be removed. The tricks you are doing require the use of volatile so that the compiler cannot remove it. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-01-04 0:38 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-11-30 9:14 [Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address nkeynes at deadcoderemoval dot net 2011-12-14 23:29 ` [Bug rtl-optimization/51353] " pinskia at gcc dot gnu.org 2011-12-15 2:16 ` nkeynes at deadcoderemoval dot net 2012-01-04 0:38 ` pinskia 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).