-03 & inlining & computed goto bug
Kent Boortz
kent@erlang.ericsson.se
Tue May 26 12:08:00 GMT 1998
problem: the resulting code is wrong if using -O3 and computed goto
version: EGCS 1.0.2, GCC 2.8.1, GCC 2.7.X
uname -a: SunOS gollum 5.5.1 Generic_103640-18 sun4u sparc SUNW,Ultra-1
command: gcc -O3 test.c
error msg: -
The program below is not running properly if inlining is used together
with -O3 optimisation. I believe it is a target independent bug, I saw
it first on gcc 2.7.X for m68k. The code below is only tested to be
incorrect on Sparc.
The problem goes away if using "gcc -O3 -fno-inline test.c".
/kgb
---------------------------------------------------------------------------
int expect_do1 = 1, expect_do2 = 2;
static int doit(int x){
__label__ lbl1;
__label__ lbl2;
static int jtab_init = 0;
static void *jtab[2];
if(!jtab_init) {
jtab[0] = &&lbl1;
jtab[1] = &&lbl2;
jtab_init = 1;
}
goto *jtab[x];
lbl1:
return 1;
lbl2:
return 2;
}
static void do1(void) {
if (doit(0) != expect_do1)
exit(1);
}
static void do2(void){
if (doit(1) != expect_do2)
exit(2);
}
int main(void){
do1();
do2();
exit(0);
}
---------------------------------------------------------------------------
More information about the Gcc-bugs
mailing list