User account creation filtered due to spam.

Bug 53917 - Wuninitialized warning points to place where variable doesn't occur
Summary: Wuninitialized warning points to place where variable doesn't occur
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.6.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2012-07-10 16:13 UTC by Paulo J. Matos
Modified: 2016-09-06 07:20 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase (153 bytes, text/x-csrc)
2012-07-10 16:13 UTC, Paulo J. Matos
Details
Another testcase (inlining issue) (263 bytes, text/x-csrc)
2012-07-10 16:38 UTC, Paulo J. Matos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paulo J. Matos 2012-07-10 16:13:24 UTC
Created attachment 27771 [details]
Testcase

Hi,

I have noticed that when compiling the following test case (will attach to the bug):

test1.c:
int a, b;
void fn1 ();
typedef enum
{
    READ_WRITE
} TAG_STATE;
TAG_STATE fn2 ();
void
fn3 ()
{
    int c;
    if (a)
        c = 0;
    else
        switch (fn2 ())
        case 0:
    c = 1;
    b = c;
    if (b)
        fn1 ();
}

gcc says:
$  gcc -Os -S -Wall test1.c
test1.c: In function 'fn3':
test1.c:19:8: warning: 'c' may be used uninitialized in this function [-Wuninitialized]

However line 19 is 'if (b)'.

Used gcc46 but also reproducible with gcc47.
Comment 1 Paulo J. Matos 2012-07-10 16:37:20 UTC
Here's another example:
void fn1 ();
typedef struct
{
    int hdr[0];
} foo;
typedef enum
{
    READ_WRITE
} bar;
typedef struct
{
    struct
    {
        foo t1;
    } mp;
} foobar;
bar fn2 ();
typedef struct
{
    foobar tag_mem_config;
} tag;
static int
fn3 (foobar * p1)
{
    int valid;
    if (p1->mp.t1.hdr[0])
        valid = 0;
    else
        switch (fn2 ())
        case 0:
    valid = 1;
    return valid;
}
void
fn4 ()
{
    tag p_t1_rw_fsm_data;
    if (fn3 (&p_t1_rw_fsm_data.tag_mem_config))
        fn1 ();
}

GCC says:
test.c: In function 'fn4':
test.c:38:8: warning: 'valid' may be used uninitialized in this function [-Wuninitialized]


Again, line 38 is: if (fn3 (&p_t1_rw_fsm_data.tag_mem_config))
In this case this looks like it's related to inlining.
Comment 2 Paulo J. Matos 2012-07-10 16:38:22 UTC
Created attachment 27772 [details]
Another testcase (inlining issue)