public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization
@ 2003-08-30 18:13 adx at swissonline dot ch
  2003-08-30 18:19 ` [Bug target/12111] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: adx at swissonline dot ch @ 2003-08-30 18:13 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: sh-hms: sibling function call fails in interrupt handler
                    with optimization
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: adx at swissonline dot ch
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i386-mingw32
GCC target triplet: sh-hms

>>Compile and build information:

C:\USER\DITT\src\4q-sh\NWR\work>c:\gcc3-sh\bin\sh-hms-c++ -v -save-temps -m2 -c
-g -O2 -Wall -Wmissing-prototypes -fno-common -I..\include
-I..\..\common\include -Wa,-ahld sibling.c >sibling.l
Reading specs from C:\GCC3-SH\BIN\..\lib\gcc-lib\sh-hms\3.3.1\specs
Configured with: ../configure --prefix=/gcc3-sh --target=sh-hms
--host=i386-mingw32 --build=i686-pc-linux-gnu -v : (reconfigured) ../configure
--prefix=/gcc3-sh --target=sh-hms --host=i386-mingw32 --build=i686-pc-linux-gnu -v
Thread model: single
gcc version 3.3.1
 C:\GCC3-SH\BIN\..\lib\gcc-lib\sh-hms\3.3.1\cc1plus.exe -E -D__GNUG__=3 -quiet
-v -I..\include -I..\..\common\include -iprefix
C:\GCC3-SH\BIN\../lib/gcc-lib/sh-hms\3.3.1\ -D__GNUC__=3 -D__GNUC_MINOR__=3
-D__GNUC_PATCHLEVEL__=1 sibling.c -m2 -Wall -Wmissing-prototypes -fno-common -O2
sibling.ii
ignoring nonexistent directory "C:/GCC3-SH/sh-hms/sys-include"
ignoring nonexistent directory "/gcc3-sh/sh-hms/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 ../include
 ../../common/include
 C:/GCC3-SH/include/c++/3.3.1
 C:/GCC3-SH/include/c++/3.3.1/sh-hms
 C:/GCC3-SH/include/c++/3.3.1/backward
 C:/GCC3-SH/lib/gcc-lib/sh-hms/3.3.1/include
 C:/GCC3-SH/sh-hms/include
 /gcc3-sh/include/c++/3.3.1
 /gcc3-sh/include/c++/3.3.1/sh-hms
 /gcc3-sh/include/c++/3.3.1/backward
 /gcc3-sh/include
 /gcc3-sh/lib/gcc-lib/sh-hms/3.3.1/include
 /gcc3-sh/sh-hms/include
End of search list.
 C:\GCC3-SH\BIN\..\lib\gcc-lib\sh-hms\3.3.1\cc1plus.exe -fpreprocessed
sibling.ii -quiet -dumpbase sibling.c -m2 -auxbase sibling -g -O2 -Wall
-Wmissing-prototypes -version -fno-common -o c:\tmp/ccjpRigb.s
GNU C++ version 3.3.1 (sh-hms)
	compiled by GNU C version egcs-2.91.66 19990314 (egcs-1.1.2 release).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32659
 C:\GCC3-SH\BIN\..\lib\gcc-lib\sh-hms\3.3.1\..\..\..\..\sh-hms\bin\as.exe
--traditional-format -big -ahld -o sibling.o c:\tmp/ccjpRigb.s

>>The bug can be reproduced using the following source code (= sibling.c above):

void int_handler()  __attribute__ ((interrupt_handler));
void 	foo(int event);

void 	int_handler(void)
{
	foo(1);
}

>>Compiling like above yields the following assembly output:

	.global	__Z11int_handlerv
__Z11int_handlerv:
	.def	.bf;	.val	.;	.scl	101;	.line	7;	.endef
	mov.l	r1,@-r15
	mov.l	r4,@-r15
	mov.l	r14,@-r15
	mov	r15,r14
	.ln	2
	mov	r14,r15
	mov.l	@r15+,r14
	mov.l	@r15+,r4
	mov.l	@r15+,r1
	jmp	@r1
	nop
	.def	.ef;	.val	.;	.scl	101;	.line	2;	.endef
	.def	__Z11int_handlerv;	.val	.;	.scl	-1;	.endef
	.ident	"GCC: (GNU) 3.3.1"

>>Obviously, r1 is not initialized with the jump address to foo. 
>>If int_handler is not defined as interrupt handler, correct code is produced:

void int_handler();
void 	foo(int event);

void 	int_handler(void)
{
	foo(1);
}

	.global	__Z11int_handlerv
__Z11int_handlerv:
	.def	.bf;	.val	.;	.scl	101;	.line	7;	.endef
	mov.l	r14,@-r15
	.ln	2
	mov	#1,r4
	mov.l	L2,r1
	.ln	1
	mov	r15,r14
	.ln	2
	mov	r14,r15
	jmp	@r1
	mov.l	@r15+,r14
L3:
	.align 2
L2:
	.long	__Z3fooi
	.def	.ef;	.val	.;	.scl	101;	.line	2;	.endef
	.def	__Z11int_handlerv;	.val	.;	.scl	-1;	.endef
	.ident	"GCC: (GNU) 3.3.1"

>>Likewise, compiling as interrupt handler with -fno-optimize-sibling-calls
option produces correct code:

	.global	__Z11int_handlerv
__Z11int_handlerv:
	.def	.bf;	.val	.;	.scl	101;	.line	7;	.endef
	mov.l	r0,@-r15
	mov.l	r1,@-r15
	mov.l	r2,@-r15
	mov.l	r3,@-r15
	mov.l	r4,@-r15
	mov.l	r5,@-r15
	.ln	2
	mov	#1,r4
	.ln	1
	mov.l	r6,@-r15
	mov.l	r7,@-r15
	mov.l	r14,@-r15
	sts.l	mach,@-r15
	sts.l	macl,@-r15
	.ln	2
	mov.l	L2,r1
	.ln	1
	sts.l	pr,@-r15
	.ln	2
	jsr	@r1
	mov	r15,r14
	.ln	3
	mov	r14,r15
	lds.l	@r15+,pr
	lds.l	@r15+,macl
	lds.l	@r15+,mach
	mov.l	@r15+,r14
	mov.l	@r15+,r7
	mov.l	@r15+,r6
	mov.l	@r15+,r5
	mov.l	@r15+,r4
	mov.l	@r15+,r3
	mov.l	@r15+,r2
	mov.l	@r15+,r1
	mov.l	@r15+,r0
	rte	
	nop
L3:
	.align 2
L2:
	.long	__Z3fooi
	.def	.ef;	.val	.;	.scl	101;	.line	3;	.endef
	.def	__Z11int_handlerv;	.val	.;	.scl	-1;	.endef
	.ident	"GCC: (GNU) 3.3.1"


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
@ 2003-08-30 18:19 ` pinskia at gcc dot gnu dot org
  2003-08-31  8:31 ` adx at swissonline dot ch
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-30 18:19 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal
          Component|c                           |target
           Keywords|                            |wrong-code


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-30 18:19 -------
I think the fix would be to disable sibcalling optimization for functions with the interrupt attribute.


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
  2003-08-30 18:19 ` [Bug target/12111] " pinskia at gcc dot gnu dot org
@ 2003-08-31  8:31 ` adx at swissonline dot ch
  2003-09-12  7:49 ` dank at kegel dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: adx at swissonline dot ch @ 2003-08-31  8:31 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From adx at swissonline dot ch  2003-08-31 08:31 -------
Sure, but this would be just a workaround, no fix. 
Besides, the bug causes unavoidably the program to crash, hence I think my
original severity level setting "critical" was appropriate.


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
  2003-08-30 18:19 ` [Bug target/12111] " pinskia at gcc dot gnu dot org
  2003-08-31  8:31 ` adx at swissonline dot ch
@ 2003-09-12  7:49 ` dank at kegel dot com
  2004-01-18 18:59 ` dhazeghi at yahoo dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dank at kegel dot com @ 2003-09-12  7:49 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


dank at kegel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dank at kegel dot com


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (2 preceding siblings ...)
  2003-09-12  7:49 ` dank at kegel dot com
@ 2004-01-18 18:59 ` dhazeghi at yahoo dot com
  2004-01-18 18:59 ` dhazeghi at yahoo dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dhazeghi at yahoo dot com @ 2004-01-18 18:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dhazeghi at yahoo dot com  2004-01-18 18:59 -------
I just attached the assembly produced by the gcc 3.4 branch. Can you verify if
it's still wrong? Thanks.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (3 preceding siblings ...)
  2004-01-18 18:59 ` dhazeghi at yahoo dot com
@ 2004-01-18 18:59 ` dhazeghi at yahoo dot com
  2004-01-19 20:29 ` adx at swissonline dot ch
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dhazeghi at yahoo dot com @ 2004-01-18 18:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dhazeghi at yahoo dot com  2004-01-18 18:59 -------
Created an attachment (id=5517)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5517&action=view)
assembly produced by gcc 3.4 branch


-- 


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


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (4 preceding siblings ...)
  2004-01-18 18:59 ` dhazeghi at yahoo dot com
@ 2004-01-19 20:29 ` adx at swissonline dot ch
  2004-01-19 20:36 ` dhazeghi at yahoo dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: adx at swissonline dot ch @ 2004-01-19 20:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From adx at swissonline dot ch  2004-01-19 20:29 -------
(In reply to comment #4)
> I just attached the assembly produced by the gcc 3.4 branch. Can you verify if
> it's still wrong? Thanks.

The code is correct. Although I am wondering why registers r8-r13 are being
saved to the stack (different to the original 3.3.1 non-optimized code). Are the
rules for register usage in interrupt handlers going to be changed in 3.4?

BTW, I now agree to comment #1. Sibcalling optimization must be disabled in
interrupt handlers. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dhazeghi at yahoo dot com


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


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (5 preceding siblings ...)
  2004-01-19 20:29 ` adx at swissonline dot ch
@ 2004-01-19 20:36 ` dhazeghi at yahoo dot com
  2004-01-19 21:53 ` adx at swissonline dot ch
  2004-01-19 21:59 ` dhazeghi at yahoo dot com
  8 siblings, 0 replies; 10+ messages in thread
From: dhazeghi at yahoo dot com @ 2004-01-19 20:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dhazeghi at yahoo dot com  2004-01-19 20:36 -------
I compiled with -O2 -fno-common -m2. That's the same as you did, right?  Thanks. If so, shall we 
close this as fixed for 3.4.0?

-- 


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


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (6 preceding siblings ...)
  2004-01-19 20:36 ` dhazeghi at yahoo dot com
@ 2004-01-19 21:53 ` adx at swissonline dot ch
  2004-01-19 21:59 ` dhazeghi at yahoo dot com
  8 siblings, 0 replies; 10+ messages in thread
From: adx at swissonline dot ch @ 2004-01-19 21:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From adx at swissonline dot ch  2004-01-19 21:53 -------
(In reply to comment #6)
> I compiled with -O2 -fno-common -m2. That's the same as you did, right? 
Thanks. If so, shall we 
> close this as fixed for 3.4.0?

Yes, may be closed.

-- 


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


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

* [Bug target/12111] sh-hms: sibling function call fails in interrupt handler with optimization
  2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
                   ` (7 preceding siblings ...)
  2004-01-19 21:53 ` adx at swissonline dot ch
@ 2004-01-19 21:59 ` dhazeghi at yahoo dot com
  8 siblings, 0 replies; 10+ messages in thread
From: dhazeghi at yahoo dot com @ 2004-01-19 21:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dhazeghi at yahoo dot com  2004-01-19 21:59 -------
Excellent. Thanks for the report!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |3.4.0


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


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

end of thread, other threads:[~2004-01-19 21:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-30 18:13 [Bug c/12111] New: sh-hms: sibling function call fails in interrupt handler with optimization adx at swissonline dot ch
2003-08-30 18:19 ` [Bug target/12111] " pinskia at gcc dot gnu dot org
2003-08-31  8:31 ` adx at swissonline dot ch
2003-09-12  7:49 ` dank at kegel dot com
2004-01-18 18:59 ` dhazeghi at yahoo dot com
2004-01-18 18:59 ` dhazeghi at yahoo dot com
2004-01-19 20:29 ` adx at swissonline dot ch
2004-01-19 20:36 ` dhazeghi at yahoo dot com
2004-01-19 21:53 ` adx at swissonline dot ch
2004-01-19 21:59 ` dhazeghi at yahoo 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).