Bug 26219 - longjmp doesn't work
Summary: longjmp doesn't work
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 09:52 UTC by Kenji Mugita
Modified: 2012-01-13 22:32 UTC (History)
2 users (show)

See Also:
Host: Cygwin1.5.19(0.150/4/2)
Target: h8300-elf
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kenji Mugita 2006-02-11 09:52:00 UTC
gcc version 4.1. 20060120
Configured with: ../configure --target=h8300-elf --prefix=/usr/local --enable-languages=c,c++ --with-newlib --with-headers=/usr/src/newlib-1.14.0/newlib/libc/include

/////////////////////////////////////
#include <setjmp.h>
jmp_buf jb_error;  
void jump(void){
	longjmp(jb_error,1);
}
void func1(void){
    return;
}
int main(void){
    setjmp(jb_error);
    func1();
    jump();
}
/////////////////////////////
This program compiled by h8300-elf-gcc(4.1) doesn't work.
The program compiled by h8300-elf-gcc(3.4.3) with same library works.
Comment 1 Richard Biener 2006-02-11 13:33:49 UTC
You need to provide a more sensible test or a description of what "works" and "does not work" for this testcase is supposed to be.
Comment 2 Kenji Mugita 2006-02-14 03:37:41 UTC
h8300-elf-gcc(3.4.3) makes this object.
	0x1a0	<main>:		6d f6             mov.w	r6,@-e7
-	0x1a2	<main+2>:		0d 76             mov.w	r7,r6
	0x1a4	<main+4>:		79 00 1d 4a       mov.w	#0x1d4a,r0
-	0x1a8	<main+8>:		5e 00 01 f0       jsr	@0x1f0:0 ; setjmp(jb_error)
-	0x1ac	<main+12>:		5e 00 01 98       jsr	@0x198:0 ; func1()
-	0x1b0	<main+16>:		5e 00 01 88       jsr	@0x188:0 ; jump()
-	0x1b4	<main+20>:		0d 20             mov.w	r2,r0
-	0x1b6	<main+22>:		6d 76             mov.w	@r7+,r6
-	0x1b8	<main+24>:		54 70             rts	

It works fine.  run-> setjmp()->func1()->jump()->setjmp() ..

h8300-elf-gcc(4.1.0) makes this object
	0x1a8	<main>:		6d f6             mov.w	r6,@-e7
-	0x1aa	<main+2>:		0d 76             mov.w	r7,r6
-	0x1ac	<main+4>:		79 02 1d 1a       mov.w	#0x1d1a,r2
-	0x1b0	<main+8>:		6d f2             mov.w	r2,@-e7
-	0x1b2	<main+10>:		5e 00 01 f8       jsr	@0x1f8:0
-	0x1b6	<main+14>:		0b 87             adds	#0x2,er7
-	0x1b8	<main+16>:		5e 00 01 a0       jsr	@0x1a0:0
-	0x1bc	<main+20>:		5e 00 01 8c       jsr	@0x18c:0
-	0x1c0	<main+24>:		6d 76             mov.w	@r7+,r6
-	0x1c2	<main+26>:		54 70             rts	

It doesn't run correctly. run-> setjmp()->func1()->jump()-> freeze(Infinite loop in jump())

In more complex program, freeze when run into longjmp().

Comment 3 Andrew Pinski 2006-02-14 03:51:36 UTC
Can you try:
#include <setjmp.h>
jmp_buf jb_error;  
void jump(void){
        longjmp(jb_error,1);
}
void func1(void){
    return;
}
int main(void){
    if(setjmp(jb_error))
       return 0;
    func1();
    jump();
}

I am wondering if you are invoking undefined behavior in calling longjmp twice on the same setjmp.
Comment 4 Andrew Pinski 2012-01-13 22:18:53 UTC
No feedback in almost 5 years so closing.