public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50171] New: False positive -Wuninitialized warning
@ 2011-08-24  0:06 kirill at shutemov dot name
  2011-08-24  3:12 ` [Bug c/50171] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kirill at shutemov dot name @ 2011-08-24  0:06 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50171
           Summary: False positive -Wuninitialized warning
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kirill@shutemov.name


Created attachment 25085
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25085
test case

$ cat test.i 
int baz(char **, const char *);
int quux(char *);

static int bar(char **out, const char *in)
{
        char *t;

        if (!baz(&t, in))
                return -1;

        *out = t;

        return 0;
}

int foo(const char *a)
{
        char *b;

        if (!bar(&b, a))
                return -1;

        return quux(b);
}
$ gcc -c -O -Wuninitialized test.i
test.i: In function ‘foo’:
test.i:23:9: warning: ‘b’ may be used uninitialized in this function
[-Wuninitialized]


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

* [Bug c/50171] False positive -Wuninitialized warning
  2011-08-24  0:06 [Bug c/50171] New: False positive -Wuninitialized warning kirill at shutemov dot name
@ 2011-08-24  3:12 ` pinskia at gcc dot gnu.org
  2011-08-24  8:17 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-08-24  3:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-08-24 00:05:25 UTC ---
int baz(char **, const char *);
int quux(char *);

int foo(const char *a)
{
        char *b;
        int t1;
{

        char *t;

        if (!baz(&t, a))
                t1 = -1

        b = t;

        t1 = 0;
}
  if (!t1)
    return -1;

        return quux(b);
}

--- CUT ---
After some more optimization:
int foo(const char *a)
{
        char *b;
        char *t;

        if (!baz(&t, a))
        ;
        else
          return -1;
        return quux(b);
}

looks like a correct uninitialized warning to me after inlinining has happened.
 b is initialized when the return value (t1) is 0 and uninitialized otherwise.


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

* [Bug c/50171] False positive -Wuninitialized warning
  2011-08-24  0:06 [Bug c/50171] New: False positive -Wuninitialized warning kirill at shutemov dot name
  2011-08-24  3:12 ` [Bug c/50171] " pinskia at gcc dot gnu.org
@ 2011-08-24  8:17 ` jakub at gcc dot gnu.org
  2011-08-24 11:17 ` kirill at shutemov dot name
  2011-08-24 11:35 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-08-24  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-08-24 06:46:44 UTC ---
Yeah, this is definitely not a false positive, but completely correct warning,
the code is buggy.  Your pseudo-inlined version isn't correct, after that t1 =
-1 you need ; goto out; and out:; after t1 = 0;.


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

* [Bug c/50171] False positive -Wuninitialized warning
  2011-08-24  0:06 [Bug c/50171] New: False positive -Wuninitialized warning kirill at shutemov dot name
  2011-08-24  3:12 ` [Bug c/50171] " pinskia at gcc dot gnu.org
  2011-08-24  8:17 ` jakub at gcc dot gnu.org
@ 2011-08-24 11:17 ` kirill at shutemov dot name
  2011-08-24 11:35 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: kirill at shutemov dot name @ 2011-08-24 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Kirill A. Shutemov <kirill at shutemov dot name> 2011-08-24 10:57:30 UTC ---
Sorry, I've made mistake trying to simplify the test case.

Is it still correct to generate warning for the code below?

int error(void);
int baz(char **, const char *);
int quux(char *);

static int bar(char **out, const char *in)
{
    char *t;
    int err;

    err = baz(&t, in);
    if (err < 0)
        return error();

    *out = t;

    return 0;
}

int foo(const char *a)
{
    int err;
    char *b;

    err = bar(&b, a);
    if (err < 0)
        return error();

    return quux(b);
}


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

* [Bug c/50171] False positive -Wuninitialized warning
  2011-08-24  0:06 [Bug c/50171] New: False positive -Wuninitialized warning kirill at shutemov dot name
                   ` (2 preceding siblings ...)
  2011-08-24 11:17 ` kirill at shutemov dot name
@ 2011-08-24 11:35 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-24 11:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-24 11:29:35 UTC ---
Yes, if error does not return a value < 0 then it will be used uninitialized.


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

end of thread, other threads:[~2011-08-24 11:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-24  0:06 [Bug c/50171] New: False positive -Wuninitialized warning kirill at shutemov dot name
2011-08-24  3:12 ` [Bug c/50171] " pinskia at gcc dot gnu.org
2011-08-24  8:17 ` jakub at gcc dot gnu.org
2011-08-24 11:17 ` kirill at shutemov dot name
2011-08-24 11:35 ` rguenth at gcc dot gnu.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).