http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55217

Michael Veksler <mickey.veksler at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mickey.veksler at gmail dot com

--- Comment #1 from Michael Veksler <mickey.veksler at gmail dot com> ---
(Strange that this hasn't been confirmed for over a year!)

I have a similar issue with gcc-4.8 with a slightly different test-case. 
So first I looked into your test case. To me it seems that gcc-4.7 warning does
look strange here, but with gcc-4.8 things look better:

----
gcc -c -O2 -Wstrict-overflow=2 beta.c -std=c99
beta.c: In function ‘f’:
beta.c:7:20: warning: assuming signed overflow does not occur when simplifying
conditional to constant [-Wstrict-overflow]
                 if (r)
                    ^
beta.c:10:17: warning: assuming signed overflow does not occur when simplifying
conditional to constant [-Wstrict-overflow]
                 for (int j = 0; j < r; j++)
---

The first warning for if(r) makes sense.
However, the second warning does not make sense. Even after removing the 'if'
the warning stays:
---
void f(int n, int s)
{
        int r = 1;
        for (int i = 1; i < n; i++)
            if (r)
                r++;
        for (int j = 0; j < r; j++)
            h(&s);
}


gamma.c:9:9: warning: assuming signed overflow does not occur when simplifying
conditional to constant [-Wstrict-overflow]
         for (int j = 0; j < r; j++)
---

It is as if gcc transforms the for loop to:
    int j=0;
    if (j >= r) goto done;  // <--- does the warning come from here?
  loop:
    h(&s);
    j++
    if (j < r) goto loop;
  done:

I assume that then gcc notices that r>=1, unless it overflows, and hence
j>=r must be false for the first j, i.e., j=0.
If this is what happens, then this is the wrong way to do it. If the same
expression is duplicated then -Wstrict-overflow should be emitted only if
it applies to both duplicates, or am I missing something?

Reply via email to