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

             Bug #: 51983
           Summary: Wrong line number in an uninitialized variable warning
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: greta.yo...@arm.com
                CC: ram...@gcc.gnu.org


For uninitialized variables of type _Complex, arm and x86 compilers report
different line numbers in warning messages:
* if only the real part of a complex variable is uninitialized, arm compiler
reports the line number where the variable is declared.
* if only the imaginary part of a complex variable is uninitialized, arm
compiler reports the line number where the variable is used.
* if only one of the parts of a complex variable is uninitialized, x86 compiler
reports the line where the other part is initialized.
* if both parts of a complex variable are uninitialized, both arm and x86
compilers (correctly) report the line where the variable is used. 

This behaviour causes a failure in gcc.dg/uninit-13.c test on arm target. 

Note that in this test, dg-warning directive expects the warning message about
uninitialized variable to report the line in which the imaginary part of the
complex variable is initialized, and not the line where the uninitialized
variable is used. That is, the test passes on x86 target, even thought the line
number in the message is not what one would (perhaps naively) expect, based on
the behaviour of the compiler for other types of uninitialized variables.

I don't know if the problem is in the frontend, middle-end, target, or
testsuite. 


----------------------------------------
$ cat -n /work/tmp/unin1.c 
     1    typedef _Complex float C;
     2    C foo(int *p)
     3    {
     4      C f;
     5      int a = *p;
     6      *p = 42 * a;
     7      __imag__ f = 0;
     8      return f;
     9    }

$ arm-none-eabi-gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin1.c
/work/tmp/unin1.c: In function 'foo':
/work/tmp/unin1.c:4:5: warning: '__real__ f' is used uninitialized in this
function [-Wuninitialized]

$ gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin1.c
/work/tmp/unin1.c: In function ‘foo’:
/work/tmp/unin1.c:7: warning: ‘__real__ f’ is used uninitialized in this
function

----------------------------------------
$ cat -n /work/tmp/unin2.c 
     1    typedef _Complex float C;
     2    C foo(int *p)
     3    {
     4      C f;
     5      int a = *p;
     6      *p = 42 * a;
     7      __real__ f = 0;
     8      return f;
     9    }

$ arm-none-eabi-gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin2.c
/work/tmp/unin2.c: In function 'foo':
/work/tmp/unin2.c:8:3: warning: '__imag__ f' is used uninitialized in this
function [-Wuninitialized]

$ gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin2.c
/work/tmp/unin2.c: In function ‘foo’:
/work/tmp/unin2.c:7: warning: ‘__imag__ f’ is used uninitialized in this
function
----------------------------------------
$ cat -n /work/tmp/unin3.c 
     1    typedef _Complex float C;
     2    C foo(int *p)
     3    {
     4      C f;
     5      int a = *p;
     6      *p = 42 * a;
     7    
     8      return f;
     9    }
$ arm-none-eabi-gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin3.c
/work/tmp/unin3.c: In function 'foo':
/work/tmp/unin3.c:8:3: warning: 'f' is used uninitialized in this function
[-Wuninitialized]

$ gcc -O -Wuninitialized -S    -o tmp.s  /work/tmp/unin3.c
/work/tmp/unin3.c: In function ‘foo’:
/work/tmp/unin3.c:8: warning: ‘f’ is used uninitialized in this function

Reply via email to