https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53917

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-09-24
     Ever confirmed|0                           |1

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Paulo J. Matos from comment #0)
> 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.

gcc8 seems to get this one right now:

$ /usr/local/bin/gcc -c -Os -S -Wall -Wextra 53917.c
53917.c: In function ‘fn3’:
53917.c:18:7: warning: ‘c’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
     b = c;
     ~~^~~
$

(In reply to Paulo J. Matos from comment #1)
> 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.

gcc still gets this one wrong though:

$ /usr/local/bin/gcc -c -Os -S -Wall -Wextra 53917_a.c
53917_a.c: In function ‘fn4’:
53917_a.c:38:8: warning: ‘valid’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
     if (fn3 (&p_t1_rw_fsm_data.tag_mem_config))
        ^
$

So confirmed for the second testcase.

Reply via email to