public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/34879]  New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os
@ 2008-01-20  4:18 pmarques at grupopie dot com
  2008-03-29 11:37 ` [Bug target/34879] " hutchinsonandy at aim dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pmarques at grupopie dot com @ 2008-01-20  4:18 UTC (permalink / raw)
  To: gcc-bugs

The test case is gcc.c-torture/execute/built-in-setjmp.c.

The __builtin_setjmp stores Y+1 in the setjmp buffer. With -O0 the first
instruction after the jmp does a "sbiw r28, 1" that restores the
original value, but for some reason, with higher optimization levels,
this instruction is optimized away, leaving R28 pointing to the wrong
address by one.

The __builtin_setjmp code:

  if (__builtin_setjmp (buf))
16a:    ce 01           movw    r24, r28
16c:    01 96           adiw    r24, 0x01       ; 1
  Notice the increment here, before storing R28

16e:    90 93 07 01     sts     0x0107, r25
172:    80 93 06 01     sts     0x0106, r24
176:    8f ee           ldi     r24, 0xEF       ; 239
178:    90 e0           ldi     r25, 0x00       ; 0
17a:    90 93 09 01     sts     0x0109, r25
17e:    80 93 08 01     sts     0x0108, r24
182:    ed b7           in      r30, 0x3d       ; 61
184:    fe b7           in      r31, 0x3e       ; 62
186:    f0 93 0b 01     sts     0x010B, r31
18a:    e0 93 0a 01     sts     0x010A, r30

The __builtin_longjmp code:

  __builtin_longjmp (buf, 1);
10c:    e0 91 08 01     lds     r30, 0x0108
110:    f0 91 09 01     lds     r31, 0x0109
114:    c0 91 06 01     lds     r28, 0x0106
118:    d0 91 07 01     lds     r29, 0x0107
11c:    80 91 0a 01     lds     r24, 0x010A
120:    90 91 0b 01     lds     r25, 0x010B

no decrement, R28 is used "as is".


-- 
           Summary: __builtin_setjmp / __builtin_longjmp fails stack frame
                    address with O2, O3 and Os
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pmarques at grupopie dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: avr-*-*


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34879


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/34879] __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os
  2008-01-20  4:18 [Bug target/34879] New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os pmarques at grupopie dot com
@ 2008-03-29 11:37 ` hutchinsonandy at aim dot com
  2008-04-04 21:41 ` eric dot weddington at atmel dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: hutchinsonandy at aim dot com @ 2008-03-29 11:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hutchinsonandy at aim dot com  2008-03-29 11:37 -------
Created an attachment (id=15395)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15395&action=view)
Setjmp patch for AVR

The attached patch is a fix for AVR target. MIPS does something similar to get
around same issue.

The real problem is with gcc builin setjmp receiver being removed by
optimizers.
Optimizers think that frame_pointer load in receiver is unneeded and remove it! 

The patch loads the frame pointer in the nonlocal_goto, making the receiver
(where it jumps to) empty, so bad optimization cannot remove it. Additionally,
it avoids the unnecessary arithmetic around frame pointer offsets.

This patch was tested and the testcase passes.

Further changes may be required in the future if AVR 24bit jumps are to be
supported.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34879


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/34879] __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os
  2008-01-20  4:18 [Bug target/34879] New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os pmarques at grupopie dot com
  2008-03-29 11:37 ` [Bug target/34879] " hutchinsonandy at aim dot com
@ 2008-04-04 21:41 ` eric dot weddington at atmel dot com
  2008-06-02 22:09 ` hutchinsonandy at gcc dot gnu dot org
  2008-06-02 23:49 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot weddington at atmel dot com @ 2008-04-04 21:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-04-04 21:40:52
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34879


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/34879] __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os
  2008-01-20  4:18 [Bug target/34879] New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os pmarques at grupopie dot com
  2008-03-29 11:37 ` [Bug target/34879] " hutchinsonandy at aim dot com
  2008-04-04 21:41 ` eric dot weddington at atmel dot com
@ 2008-06-02 22:09 ` hutchinsonandy at gcc dot gnu dot org
  2008-06-02 23:49 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2008-06-02 22:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hutchinsonandy at gcc dot gnu dot org  2008-06-02 22:09 -------
Subject: Bug 34879

Author: hutchinsonandy
Date: Mon Jun  2 22:08:25 2008
New Revision: 136297

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136297
Log:
PR target/34879
* config/avr/avr.c (TARGET_BUILTIN_SETJMP_FRAME_VALUE): Redefine.
(avr_builtin_setjmp_frame_value): New function.
* config/avr/avr.md (nonlocal_goto_receiver): Define.
(nonlocal_goto): Define.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.md


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34879


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/34879] __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os
  2008-01-20  4:18 [Bug target/34879] New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os pmarques at grupopie dot com
                   ` (2 preceding siblings ...)
  2008-06-02 22:09 ` hutchinsonandy at gcc dot gnu dot org
@ 2008-06-02 23:49 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot weddington at atmel dot com @ 2008-06-02 23:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from eric dot weddington at atmel dot com  2008-06-02 23:48 -------
Fixed in 4.4.0.


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34879


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-02 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-20  4:18 [Bug target/34879] New: __builtin_setjmp / __builtin_longjmp fails stack frame address with O2, O3 and Os pmarques at grupopie dot com
2008-03-29 11:37 ` [Bug target/34879] " hutchinsonandy at aim dot com
2008-04-04 21:41 ` eric dot weddington at atmel dot com
2008-06-02 22:09 ` hutchinsonandy at gcc dot gnu dot org
2008-06-02 23:49 ` eric dot weddington at atmel dot com

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).