Deadly optimization bug (all versions!)

James Stevenson James@linux.home
Fri Oct 1 00:00:00 GMT 1999


Hi


if you mean compile it like

gcc bug.c -O1 
gcc bug.c -O2 

it worked fine on my system both
RH6.0
gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

output both compiles
ret=0
ret=1
ret=1

cya
	James

On Tue, 17 Aug 1999 08:07:01 GMT, Alex Vinokur <alexander.vinokur@telrad.co.il> wrote:
>In article <7p8scr$krk$1@techftp.technion.ac.il>,
>  Veksler Michael <mveksler@technion.ac.il> wrote:
>>
>>
>> The bug shows itself on gcc-2.7.2.1, egcs-1.0.1, egcs-1.1.2, gcc-2.95.
>> On AIX-4.1, Linux-x86 (RH4.2 and RH6.0).
>>
>> Just try to compile the following code once with -O and once without.
>> This may be the reason behind some of the problems with Linux-2.2.xx
>>
>> (I post this here, instead of gnu.gcc.bugs, since my previous
>> posts did not reach the group).
>>
>> The code:
>>
>> ---------- bug.c --------
>>
>> #include <stdio.h>
>>
>> /* If one=1, then the output should be: bit&1 */
>> unsigned test(unsigned one , unsigned  bit)
>> {
>>     unsigned val=  bit & 1;
>>     unsigned zero= one >> 1;
>>
>>     val++;
>      printf (""); // It is an unnecessary line.
>	           // All optimzation options work OK with this line.
>		   //-------------------------------------------------
>		   // Optimzation options -O1 and -O2 produce
>		   // invalid results without this line
>		   //-------------------------------------------------
>		   // egcs-2.91.57 19980901 (egcs-1.1 release)
>		   // SunOS 5.6
>		   // So, it seems to be a compiler bug.
>		   //-------------------------------------------------
>
>>     return zero + ( val>> 1 );
>> }
>>
>> int main()
>> {
>>   printf("ret=%d\n", test(1,0)); /* should print 0 */
>>   printf("ret=%d\n", test(1,1)); /* should print 1 */
>>   printf("ret=%d\n", test(1,65535)); /* should print 1 */
>>
>>   return 0;
>> }
>>
>>
>
>	Alex
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.


-- 
---------------------------------------------
Check Out: http://www.users.zetnet.co.uk/james/
E-Mail: mistral@stevenson.zetnet.co.uk
 12:40pm  up 11:49,  3 users,  load average: 2.00, 2.00, 2.00


More information about the Gcc-help mailing list