This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
grokfield miscompiled with -O9
> No. Someone should sit down and figure out what the actual problem
> is.
Ok. Here is as far as I got. grokfield gets miscompiled under certain
circumstances, passing incorrect (out-of-range) decl_context values to
grokdeclarator. I've trimmed-down the source of c-decl.c to a minimum
size. I also attach the corresponding assembler code, obtained with
-O9, on i586-pc-linux-gnu, with 2.96 19991222.
Please note that the fragment
push_obstacks_nochange ();
value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
is compiled to
call push_obstacks_nochange
testl %edi, %edi
setne %al
pushl $0
addl $3, %eax
pushl %eax
pushl %ebx
pushl %esi
call grokdeclarator
The optimization being done here is that FIELD+1 == BITFIELD, so if
edi (==width) is not null, 3+1 should be pushed, otherwise
3. Unfortunately, the high part of eax is not cleared, so it pushes
garbage. Under slight modification of the source, it produces the
fragment
pushl $0
andl $255, %eax
addl $3, %eax
instead, which is correct.
I could not convert this into a test case, because calling grokfield
from main results in inlining of grokfield (at -O9), which does not
trigger the bug.
If you need any further information, please let me know.
Regards,
Martin
bug.c
bug.s