[LinuxBIOS] ROMCC bug
Steve Magnani
steve at digidescorp.com
Sat Jun 18 04:45:51 CEST 2005
I've stumbled across a ROMCC bug that results in incorrect code being
generated. As near as I can tell, multi-layer "if" statements are at risk
of being miscompiled when optimization is enabled. The following program
snippet induces the bug when compiled via "romcc -mcpu=p4 -O2" (or -O):
/************************************************/
void die(void)
{
}
static void miscompiled_function(unsigned short param)
{
unsigned int data = __builtin_inl(0);
if (data == 0)
param = 12;
else if (data == 4)
param = 42;
else
die();
__builtin_outl(param, 0);
}
static void internal_compiler_error(unsigned short param)
{
unsigned int data = __builtin_inl(0);
if (data == 0)
param = 12;
if (data == 4)
param = 42;
if ((data != 0) && (data != 4))
die();
__builtin_outl(param, 0);
}
void main(void)
{
miscompiled_function(0);
// internal_compiler_error(0);
}
/************************************************/
The assembly output for the miscompiled function is such that when data ==
4, param is set to zero, instead of 42.
The function 'internal_compiler_error' is logically equivalent to
'miscompiled_function', but attempting to call it results in the following
message:
bug.c:20.1: bug.c:36.32: warning: edge:
bug.c:20.1: bug.c:36.32: warning: 0x9e53b08 copy
:0.0: warning: 0x9e542d8 convert
<built-in>:1.0: bug.c:21.42: bug.c:36.32: warning: def:
<built-in>:1.0: bug.c:21.42: bug.c:36.32: warning: 0x9e53ea8 __inl
<built-in>:1.0: bug.c:21.42: bug.c:36.32:
0x9e53ea8 __inl Internal compiler error: live range with already used
color %eax
Aborted
-----------------------------
Steve Magnani
www.digidescorp.com
More information about the coreboot
mailing list