Re: GCC optimization bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 17, 2017 at 6:15 PM, anubhav <anubhav@xxxxxxxxxxxxxx> wrote:
> Hello,
>
> The following code prints different results when run with different
> optimization levels (O0 vs O2).
>
> int main() {
>         int i = INT_MAX - 5;
>         int j = 0;
>         for (; i <= INT_MAX - 2; i += 3) {
>                 if (i <= 1) {
>                         j = 1;
>                 }
>         }
>         printf("%d",j);
>         return 0;
> }
>
> Commands used :
>  gcc -O0 -fno-strict-overflow bug.c -o bug        # Output is 1
>  gcc -O2 -fno-strict-overflow bug.c -o bug        # Output is 0
>
> GCC version :
> gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~16.04)
>
> The expected output is 1 since the value of i overflows once.

In C, integer overflow is an undefined behavior.

Regards,
lee

>  Is this an
> optimization bug?
>
> Thanks and regards,
> Anubhav
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux