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