This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC optimization bug?
- From: Jeffrey Walton <noloader at gmail dot com>
- To: anubhav <anubhav at cse dot iitb dot ac dot in>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 17 Jan 2017 05:23:53 -0500
- Subject: Re: GCC optimization bug?
- Authentication-results: sourceware.org; auth=none
- References: <8bd91f0702cba1bb8ea712e572a52c3b@cse.iitb.ac.in>
- Reply-to: noloader at gmail dot com
> 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
Also see Signed Overflow, http://www.airs.com/blog/archives/120 .
Jeff