public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30542]  New: gcc 4.1.1 missing uninitialized variable warnings
@ 2007-01-22 14:29 david dot cuthbert at gmail dot com
  2007-01-22 14:31 ` [Bug c/30542] " david dot cuthbert at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: david dot cuthbert at gmail dot com @ 2007-01-22 14:29 UTC (permalink / raw)
  To: gcc-bugs

Not sure if this is a bug, or I'm just missing some option or other, but I
appear to be missing "uninitialized variable" warnings (in some cases, but not
others) when compiling C such as the following:

#include <stdio.h>

int
main(void)
{
    int foo;
    int i;

    i = 1;
    while (i) {
        if (i == 10) {
            foo = 50;
        }

        /* Uncomment this block and warnings miraculously appear
        if (i == 15) {
            foo = 52;
        }
        */

        if (foo) {
            printf("%d\n", foo);
        }

        ++i;
        if (i > 20) {
            break;
        }
    }

    return 0;
}

I'm using the following to compile (which gives no output from gcc):
- /usr/bin/gcc -Wall -W -ansi -pedantic -O2 -o foo foo.c

And output from gcc -v gives this:
: gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.1-r3/work/gcc-4.1.1/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.1
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --enable-secureplt --disable-libunwind-exceptions
--disable-multilib --disable-libmudflap --disable-libssp --disable-libgcj
--enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.1 (Gentoo 4.1.1-r3)


Someone also tried the same code on 4.1.2 and got the same results (if that
helps).


-- 
           Summary: gcc 4.1.1 missing uninitialized variable warnings
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: david dot cuthbert at gmail dot com


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] gcc 4.1.1 missing uninitialized variable warnings
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
@ 2007-01-22 14:31 ` david dot cuthbert at gmail dot com
  2007-01-22 17:27 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: david dot cuthbert at gmail dot com @ 2007-01-22 14:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from david dot cuthbert at gmail dot com  2007-01-22 14:31 -------
Created an attachment (id=12931)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12931&action=view)
foo.i file

Adding foo.i file


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] gcc 4.1.1 missing uninitialized variable warnings
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
  2007-01-22 14:31 ` [Bug c/30542] " david dot cuthbert at gmail dot com
@ 2007-01-22 17:27 ` pinskia at gcc dot gnu dot org
  2007-01-23  3:09 ` muntyan at tamu dot edu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-22 17:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-01-22 17:27 -------


*** This bug has been marked as a duplicate of 22456 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] gcc 4.1.1 missing uninitialized variable warnings
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
  2007-01-22 14:31 ` [Bug c/30542] " david dot cuthbert at gmail dot com
  2007-01-22 17:27 ` pinskia at gcc dot gnu dot org
@ 2007-01-23  3:09 ` muntyan at tamu dot edu
  2007-08-15 15:21 ` manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: muntyan at tamu dot edu @ 2007-01-23  3:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from muntyan at tamu dot edu  2007-01-23 03:09 -------
Is it really quite as 22456? That bug is about variable used for initializing
itself, and really strange do-nothing code, while this one is straightforward
use of unitialized variable:

int main (void)
{
  int i, foo;
  for (i = 0; i < 10; i++)
  {
    if (i > 5)
      foo = 8;
    printf ("%d\n", foo); /* uninitialized foo is printed six times */
  }
}

or this one:

#include <stdio.h>

int func (void)
{
    return 0;
}

int main (void)
{
    int foo;

    if (func ())
        foo = 8;

    printf ("%d\n", foo);
    return 0;
}

Sorry for pain if this really a duplicate.


-- 

muntyan at tamu dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muntyan at tamu dot edu


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] gcc 4.1.1 missing uninitialized variable warnings
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
                   ` (2 preceding siblings ...)
  2007-01-23  3:09 ` muntyan at tamu dot edu
@ 2007-08-15 15:21 ` manu at gcc dot gnu dot org
  2009-02-07 21:12 ` [Bug c/30542] missing uninitialized variable warning (CCP) manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-08-15 15:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2007-08-15 15:21 -------
(In reply to comment #3)
> Is it really quite as 22456? That bug is about variable used for initializing
> itself, and really strange do-nothing code, while this one is straightforward
> use of unitialized variable:
> 
> int main (void)
> {
>   int i, foo;
>   for (i = 0; i < 10; i++)
>   {
>     if (i > 5)
>       foo = 8;
>     printf ("%d\n", foo); /* uninitialized foo is printed six times */
>   }
> }

I get ten times 8 printed. Roughly, an optimisation pass is assuming that the
initial value of foo is 8 (remember, undefined means we can assume whatever),
so foo is completely removed. Believe me, the optimisation is valid and
beneficial and in many situations the uninitialised value is never used (if we
were to warn, it will be a false positive). Unfortunately, this is not one of
these cases.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] missing uninitialized variable warning (CCP)
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
                   ` (3 preceding siblings ...)
  2007-08-15 15:21 ` manu at gcc dot gnu dot org
@ 2009-02-07 21:12 ` manu at gcc dot gnu dot org
  2009-02-07 21:12 ` manu at gcc dot gnu dot org
  2009-06-17 12:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-07 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from manu at gcc dot gnu dot org  2009-02-07 21:11 -------
This is clearly CCP. Probably a duplicate of 18501, better double check if
18501 is ever fixed.

The reason why uncommenting the block of code brings back the warning is that
CCP cannot assume that foo is just 50 because it could also be 52, so it
doesn't remove foo and then the late pass kicks in and detects a default
definition in the PHI node. I bet the warning given is "may be used".


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |18501
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |
            Summary|gcc 4.1.1 missing           |missing uninitialized
                   |uninitialized variable      |variable warning (CCP)
                   |warnings                    |


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] missing uninitialized variable warning (CCP)
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
                   ` (4 preceding siblings ...)
  2009-02-07 21:12 ` [Bug c/30542] missing uninitialized variable warning (CCP) manu at gcc dot gnu dot org
@ 2009-02-07 21:12 ` manu at gcc dot gnu dot org
  2009-06-17 12:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-07 21:12 UTC (permalink / raw)
  To: gcc-bugs



-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-02-07 21:12:23
               date|                            |


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/30542] missing uninitialized variable warning (CCP)
  2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
                   ` (5 preceding siblings ...)
  2009-02-07 21:12 ` manu at gcc dot gnu dot org
@ 2009-06-17 12:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-17 12:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2009-06-17 12:06 -------


*** This bug has been marked as a duplicate of 18501 ***


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-06-17 12:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-22 14:29 [Bug c/30542] New: gcc 4.1.1 missing uninitialized variable warnings david dot cuthbert at gmail dot com
2007-01-22 14:31 ` [Bug c/30542] " david dot cuthbert at gmail dot com
2007-01-22 17:27 ` pinskia at gcc dot gnu dot org
2007-01-23  3:09 ` muntyan at tamu dot edu
2007-08-15 15:21 ` manu at gcc dot gnu dot org
2009-02-07 21:12 ` [Bug c/30542] missing uninitialized variable warning (CCP) manu at gcc dot gnu dot org
2009-02-07 21:12 ` manu at gcc dot gnu dot org
2009-06-17 12:07 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).