Possible bug in optimization

Chris Croswhite ccroswhite@get2chip.com
Tue Feb 18 20:30:00 GMT 2003


How is this casting & masking undefined in O but -g works OKAY?  Also, why
does 2.95.x treat this as expected?  Also, Sun, HP and Intel compilers treat
this as expected?  What am I not understanding about c/c++ standard?

TIA,
Chris

Zack Weinberg said:
> Chris Croswhite <ccroswhite@get2chip.com> writes:
>
>> Here is a simple prog that I think might illustrate a bug in
>> gcc-3.2.1/2 optimization:
>
> 'Fraid not.
>
>> #include <stdio.h>
>> int main(int argc, char **argv)
>> {
>>   long long val = 0x4000000000000001;
>>   (((int*) &val)[1]) &= 0x0;
>
> This line causes undefined behavior.  GCC is allowed to reduce your
> code to smoking rubble.
>
>>   printf("%lld\n", val);
>>   return 1;
>> }
>
> zw





More information about the Gcc-bugs mailing list