public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/36550]  New: Wrong "may be used uninitialized" warning
@ 2008-06-17  9:53 aldot at gcc dot gnu dot org
  2008-06-17 10:41 ` [Bug middle-end/36550] " belyshev at depni dot sinp dot msu dot ru
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: aldot at gcc dot gnu dot org @ 2008-06-17  9:53 UTC (permalink / raw)
  To: gcc-bugs

Yet another one. It behaves the same for 4.1.2 and current trunk.

$ gcc -Os -Wuninitialized -c uninit-J.c
uninit-J.c: In function 'pr':
uninit-J.c:7: warning: 'bug' may be used uninitialized in this function

$ cat uninit-J.c
/* { dg-do compile } */
/* { dg-options "-Os -Wuninitialized" } */
void bail(void) __attribute__((noreturn));
unsigned check(void);
int pr(char**argv)
{
        char *bug;
        if (check()) {
                if (*argv)
                        bug = *++argv;
        } else {
                bug = *argv++;
                if (!*argv)
                        bail();
        }
        /* now bug is set except if (check() && !*argv) */
        if (check()) {
                if (!*argv)
                        return 0;
        }
        /* if we ever get here then bug is set */
        return *bug != 'X';
}


-- 
           Summary: Wrong "may be used uninitialized" warning
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: aldot at gcc dot gnu dot org
OtherBugsDependingO 24639
             nThis:


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
@ 2008-06-17 10:41 ` belyshev at depni dot sinp dot msu dot ru
  2008-06-17 10:47 ` aldot at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: belyshev at depni dot sinp dot msu dot ru @ 2008-06-17 10:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from belyshev at depni dot sinp dot msu dot ru  2008-06-17 10:40 -------
check() can return 1 on the first call and 0 on the second and if *argv is NULL
then then "bug" will be used uninitialized.


-- 


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
  2008-06-17 10:41 ` [Bug middle-end/36550] " belyshev at depni dot sinp dot msu dot ru
@ 2008-06-17 10:47 ` aldot at gcc dot gnu dot org
  2008-06-17 13:25 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: aldot at gcc dot gnu dot org @ 2008-06-17 10:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from aldot at gcc dot gnu dot org  2008-06-17 10:46 -------
(In reply to comment #1)
> check() can return 1 on the first call and 0 on the second and if *argv is NULL
> then then "bug" will be used uninitialized.

right, but this doesn't matter here. Better testcase:

/* { dg-do compile } */
/* { dg-options "-Os -Wuninitialized" } */
void bail(void) __attribute__((noreturn));
unsigned once(void);
int pr(char**argv)
{
        char *bug;
        unsigned check = once();
        if (check) {
                if (*argv)
                        bug = *++argv;
        } else {
                bug = *argv++;
                if (!*argv)
                        bail();
        }
        /* now bug is set except if (check && !*argv) */
        if (check) {
                if (!*argv)
                        return 0;
        }
        /* if we ever get here then bug is set */
        return *bug != 'X';
}


-- 


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
  2008-06-17 10:41 ` [Bug middle-end/36550] " belyshev at depni dot sinp dot msu dot ru
  2008-06-17 10:47 ` aldot at gcc dot gnu dot org
@ 2008-06-17 13:25 ` pinskia at gcc dot gnu dot org
  2008-08-18 17:30 ` [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs) manu at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-06-17 13:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2008-06-17 13:24 -------
This really needs conditional phis so ...


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-06-17 13:25 ` pinskia at gcc dot gnu dot org
@ 2008-08-18 17:30 ` manu at gcc dot gnu dot org
  2008-11-06 21:12 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-18 17:30 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         |2008-08-18 17:29:25
               date|                            |
            Summary|Wrong "may be used          |Wrong "may be used
                   |uninitialized" warning      |uninitialized" warning
                   |                            |(conditional PHIs)


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-08-18 17:30 ` [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs) manu at gcc dot gnu dot org
@ 2008-11-06 21:12 ` pinskia at gcc dot gnu dot org
  2009-02-04  0:09 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-11-06 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2008-11-06 21:11 -------
*** Bug 38037 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |edwintorok at gmail dot com


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-11-06 21:12 ` pinskia at gcc dot gnu dot org
@ 2009-02-04  0:09 ` pinskia at gcc dot gnu dot org
  2009-02-07 15:06 ` manu at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-04  0:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2009-02-04 00:09 -------
*** Bug 39088 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |av1474 at comtv dot ru


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-02-04  0:09 ` pinskia at gcc dot gnu dot org
@ 2009-02-07 15:06 ` manu at gcc dot gnu dot org
  2009-02-12 11:22 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-07 15:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2009-02-07 15:05 -------
*** Bug 27289 has been marked as a duplicate of this bug. ***


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fnf at specifix dot com


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2009-02-07 15:06 ` manu at gcc dot gnu dot org
@ 2009-02-12 11:22 ` manu at gcc dot gnu dot org
  2009-02-12 11:45 ` manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-12 11:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from manu at gcc dot gnu dot org  2009-02-12 11:22 -------
*** Bug 39133 has been marked as a duplicate of this bug. ***


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |corinl at gmx dot de


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2009-02-12 11:22 ` manu at gcc dot gnu dot org
@ 2009-02-12 11:45 ` manu at gcc dot gnu dot org
  2009-02-12 21:53 ` corinl at gmx dot de
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-12 11:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from manu at gcc dot gnu dot org  2009-02-12 11:45 -------
I added this as Problem 5 in the wiki:

http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings


-- 


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2009-02-12 11:45 ` manu at gcc dot gnu dot org
@ 2009-02-12 21:53 ` corinl at gmx dot de
  2009-02-12 22:06 ` manu at gcc dot gnu dot org
  2010-04-20 23:55 ` davidxl at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: corinl at gmx dot de @ 2009-02-12 21:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from corinl at gmx dot de  2009-02-12 21:53 -------
I do not really understand problem 5 for the case when the only dependancy for
the code-path check is a local variable. In this case the value cannot be
change by any other code than existing between the two checks, so this case
should be handled reliable for sure. Of course this is not possible with global
oder class variables which might be affected by some other thread.


-- 


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2009-02-12 21:53 ` corinl at gmx dot de
@ 2009-02-12 22:06 ` manu at gcc dot gnu dot org
  2010-04-20 23:55 ` davidxl at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-12 22:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from manu at gcc dot gnu dot org  2009-02-12 22:05 -------
(In reply to comment #9)
> I do not really understand problem 5 for the case when the only dependancy for
> the code-path check is a local variable. In this case the value cannot be
> change by any other code than existing between the two checks, so this case
> should be handled reliable for sure.

Should? I guess you meant "could". Because it is obviously not handled right
now at the moment of warning.

That page simply lists causes, testcases and possible solutions for existing
problems. As always, contributions are welcome.


-- 


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
  2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2009-02-12 22:06 ` manu at gcc dot gnu dot org
@ 2010-04-20 23:55 ` davidxl at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: davidxl at gcc dot gnu dot org @ 2010-04-20 23:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from davidxl at gcc dot gnu dot org  2010-04-20 23:55 -------
(In reply to comment #2)
> (In reply to comment #1)
> > check() can return 1 on the first call and 0 on the second and if *argv is NULL
> > then then "bug" will be used uninitialized.
> 
> right, but this doesn't matter here. Better testcase:
> 
> /* { dg-do compile } */
> /* { dg-options "-Os -Wuninitialized" } */
> void bail(void) __attribute__((noreturn));
> unsigned once(void);
> int pr(char**argv)
> {
>         char *bug;
>         unsigned check = once();
>         if (check) {
>                 if (*argv)
>                         bug = *++argv;
>         } else {
>                 bug = *argv++;
>                 if (!*argv)
>                         bail();
>         }
>         /* now bug is set except if (check && !*argv) */
>         if (check) {
>                 if (!*argv)
>                         return 0;
>         }
>         /* if we ever get here then bug is set */
>         return *bug != 'X';
> }
> 


The example is a little tricky for the compiler to reason because of the
'++argv'. Predicate analysis
(http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00706.html -- with additional fix
to a never return handling) will catch the following case (while the trunk gcc
does not):


void bail(void) __attribute__((noreturn));
int foo(void);
unsigned once(void);
int pr(char**argv)
{
        char *bug;
        unsigned check = once();
        char * a = *argv;
        if (check) {
                if (a)
                        bug = *++argv;
        } else {
                bug = *argv++;
                if (!*argv)
                        bail();
        }

        if (foo ())
          once();

        /* now bug is set except if (check && !*argv) */
        if (check) {
                if (!a || !*argv)
                        return 0;
        }
        /* if we ever get here then bug is set */
        return *bug != 'X';
}


-- 

davidxl at gcc dot gnu dot org changed:

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


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


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

* [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs)
       [not found] <bug-36550-4@http.gcc.gnu.org/bugzilla/>
@ 2011-04-17 22:18 ` vincent.riviere at freesbee dot fr
  0 siblings, 0 replies; 14+ messages in thread
From: vincent.riviere at freesbee dot fr @ 2011-04-17 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Vincent Riviere <vincent.riviere at freesbee dot fr> 2011-04-17 22:17:35 UTC ---
Created attachment 24023
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24023
Very simple testcase

I hit the "may be used uninitialized in this function" bug when compiling this
small testcase. I think it is the same as the bug described here.

$ gcc -c bug.c -Os -Wuninitialized
bug.c: In function 'f':
bug.c:9: warning: 'b' may be used uninitialized in this function

This happens with:
- GCC 4.4.5 (Debian 4.4.5-8) for the target i486-linux-gnu
- GCC 4.5.2 for the target m68k-atari-mint


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

end of thread, other threads:[~2011-04-17 22:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-17  9:53 [Bug middle-end/36550] New: Wrong "may be used uninitialized" warning aldot at gcc dot gnu dot org
2008-06-17 10:41 ` [Bug middle-end/36550] " belyshev at depni dot sinp dot msu dot ru
2008-06-17 10:47 ` aldot at gcc dot gnu dot org
2008-06-17 13:25 ` pinskia at gcc dot gnu dot org
2008-08-18 17:30 ` [Bug middle-end/36550] Wrong "may be used uninitialized" warning (conditional PHIs) manu at gcc dot gnu dot org
2008-11-06 21:12 ` pinskia at gcc dot gnu dot org
2009-02-04  0:09 ` pinskia at gcc dot gnu dot org
2009-02-07 15:06 ` manu at gcc dot gnu dot org
2009-02-12 11:22 ` manu at gcc dot gnu dot org
2009-02-12 11:45 ` manu at gcc dot gnu dot org
2009-02-12 21:53 ` corinl at gmx dot de
2009-02-12 22:06 ` manu at gcc dot gnu dot org
2010-04-20 23:55 ` davidxl at gcc dot gnu dot org
     [not found] <bug-36550-4@http.gcc.gnu.org/bugzilla/>
2011-04-17 22:18 ` vincent.riviere at freesbee dot fr

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).