egcs 1.1.2 (egcs-2.91.66) bug report (core dump with -O, -O2 option)

Aki Niimura akineko@worldnet.att.net
Tue Mar 30 15:20:00 GMT 1999


g++ bug report
 
Reporter : Aki Niimura  neko@my-dejanews.com Date : 
03/30/99  
 
g++ version : egcs 1.1.2 
(egcs-2.91.66) Environment : % uname -a SunOS Evelyn 5.7 Generic sun4m 
sparc SUNW,SPARCstation-4  
 
Bug description : The attached 
program runs correctly *if* compiled with no optimization. But it will core 
dump if compiled with optimization option (-O, -O2). Although I haven't 
confirmed, this bug seems also in the previous releases. I have tried to de-mystify this, but I couldn't 
figure out what exactly the problem is.  
 
// a session log
 
% g++ test.cc % aout a.out a 
@0 b @10 c @20 a @21 % g++ -O test.cc % a.out a @0 b 
@10 Segmentation Fault (core dumped)   <<=== % g++ -O2 
test.cc % a.out a @0 b @10 Segmentation Fault (core 
dumped)   <<=== %  
 
// gdb log %gdb a.out  
(compiled with -O)  
.....  
(gdb) run Starting program: 
/export/home/neko/tmp/a.out a @0 b @10  
 
Program received signal SIGSEGV, 
Segmentation fault. 0x1a470 in T::test (this=20, _f=false) at 
test.cc:35 35  if($time < $till) return; (gdb)  
 
// A test program which can reproduce 
this bug
 
      1 
#include <iostream.h>       2 #include 
<setjmp.h>       3 
      4       5 int 
$time;       6       7 
class T {       8 
public:       9     T() { 
};            
     10      
11     void test(bool _f);      12 
};      13      14 
void      15 T::test(bool _f)      
16 {      17     static bool _f2 = 
false;      18     static jmp_buf 
$env;      19     static int 
$till;      20      
21     if(_f) { _f2 = false; return; 
}      22      
23     if(_f2) longjmp($env, 1);      
24     else _f2 = true;      25 
     26     cout << "a 
@" << $time << endl;      27 
     28     $till = 
$time+10;      29     if(setjmp($env) 
== 0) return;      30     if($time 
< $till) return;      31     cout 
<< "b @" << $time << 
endl;      32      
33     $till = $time+10;      
34     if(setjmp($env) == 0) 
return;      35     if($time < 
$till) return;      36     cout 
<< "c @" << $time << 
endl;      37      
38     _f2 = false;      39 
}      40      41 
main()      42 {      
43     T test;      44 
     45     $time = 
0;      46     
test.test(true);      47     for(int 
i = 0; i < 25; ++i, ++$time)    
test.test(false);      48 }      
49  
 



More information about the Gcc-bugs mailing list