/* Test program to display a possible GCC bug. * Submitted by Richard Mitton (richard.mitton@bigfoot.com) * 15th August 2000. * * Using a DJGPP system (latest version, v2.03), Windows 98. * (latest version, gcc 2.95.2 19991024 release): * * To make bug happen: gcc -S -O -fomit-frame-pointer test.c -o test.s * To make bug not happen, remove either -O or -fomit-frame-pointer. * * The bug happens when GCC throws away the result from GetValue(). */ #include /* Just some functions to demonstrate */ unsigned char GetValue(void); unsigned char EmptyFunction(void); void Print(int a); void DoNothing(int b); int main(void) { unsigned char foo, bar, flag; /* IMPORTANT PART! * This should print GetValue()+1. * Since GetValue always returns 10, it should print 11. */ foo = GetValue() + 1; Print(foo); /* From here on is just misc code, but if I take any of it out then * the bug doesn't happen... */ foo = EmptyFunction(); bar = EmptyFunction(); flag = foo; DoNothing(bar); DoNothing(bar); if (!flag) foo = 1; return 0; } /* Always return 10 */ unsigned char GetValue(void) { return 10; } unsigned char EmptyFunction(void) { return 0; } void Print(int a) { printf("Answer is %i, but should be 11 (i.e. 10+1).\n", a); } void DoNothing(int b) { }