Bug 24004 - [4.0 Regression] bogus 'may be uninit warnings' for loops
[4.0 Regression] bogus 'may be uninit warnings' for loops
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: middle-end
4.0.2
: P2 normal
: 4.1.1
Assigned To: Not yet assigned to anyone
: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2005-09-21 22:11 UTC by Dan Hollis
Modified: 2007-02-03 15:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0 4.1.1 4.1.2 3.4.0
Known to fail: 4.0.0 4.0.3
Last reconfirmed: 2005-12-02 00:10:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Hollis 2005-09-21 22:11:55 UTC
$ cat /etc/fedora-release 
Fedora Core release 4 (Stentz)


$ uname -a
Linux host 2.6.13.1 #4 Sat Sep 17 10:57:37 PDT 2005 x86_64 x86_64 x86_64 GNU/Linux


$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)


testcase.c:
===========
#include <math.h>
typedef float vec_t;
typedef vec_t vec3_t[3];

void VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out ) {
        out[0] = veca[0] - vecb[0];
        out[1] = veca[1] - vecb[1];
        out[2] = veca[2] - vecb[2];
}

void VectorCopy( const vec3_t in, vec3_t out ) {
        out[0] = in[0];
        out[1] = in[1];
        out[2] = in[2];
}

vec_t VectorLength( const vec3_t v ) {
        return sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
}

float BG_SplineLength( void ) {
        float i;
        float granularity = 0.01f;
        float dist = 0;
        vec3_t  vec[2];
        vec3_t lastPoint;
        vec3_t result;

        for(i = 0; i <= 1.f; i += granularity ) {

                VectorSubtract( vec[1], vec[0], result );

                if( i != 0 ) {
                        VectorSubtract( result, lastPoint, vec[0] );
                        dist += VectorLength( vec[0] );
                }

                VectorCopy( result, lastPoint );
        }
        return dist;
}

int main( void ) {
        BG_SplineLength();
        return 0;
}


$ gcc -O2 -Wall -o testcase testcase.c 
$ gcc -O3 -Wall -o testcase testcase.c 
testcase.c: In function ‘BG_SplineLength’:
testcase.c:26: warning: ‘lastPoint[0]’ may be used uninitialized in this function
testcase.c:26: warning: ‘lastPoint[1]’ may be used uninitialized in this function
testcase.c:26: warning: ‘lastPoint[2]’ may be used uninitialized in this function
testcase.c: In function ‘main’:
testcase.c:26: warning: ‘lastPoint[0]’ may be used uninitialized in this function
testcase.c:26: warning: ‘lastPoint[1]’ may be used uninitialized in this function
testcase.c:26: warning: ‘lastPoint[2]’ may be used uninitialized in this function


gcc3.2 and 3.3 don't produce these bogus warnings.
Comment 1 Dan Hollis 2005-12-01 23:57:34 UTC
still present in 4.0.2
Comment 2 Andrew Pinski 2005-12-02 00:10:15 UTC
Note the warning is that bogus, take the following example:
float a(void)
{
        float i;
        float granularity = 0.01f;
        float dist = 0;
        float vec[2] = {0,0};
        float lastPoint;
        float result;

        for(i = 0; i <= 1.f; i += granularity ) {

                result = vec[1] - vec[0];

                if( i != 0 ) {
                        vec[0] = result - lastPoint;
                        dist += vec[0];
                }

                lastPoint = result;
        }
        return dist;
}

We get the same warning.  For the mainline, we get no warning as we are jump threading so that the if (i!=0) is removed for the first iteration of the loop.
Comment 3 Dan Hollis 2006-01-23 12:32:00 UTC
so is this a bug or not a bug? or user error?
Comment 4 Gabriel Dos Reis 2007-02-03 15:44:16 UTC
Fixed in GCC-4.1.1 and higher.