public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union
@ 2012-10-04  0:28 eggert at gnu dot org
  2012-10-04  8:07 ` [Bug middle-end/54804] " manu at gcc dot gnu.org
  2021-03-25 23:13 ` msebor at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: eggert at gnu dot org @ 2012-10-04  0:28 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54804
           Summary: -Wuninitialized fails to warn about uninitialized
                    local union
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org


This problem stems from a proposed change to Bison to work
around a GCC bug.  I'd rather get the GCC bug fixed, so I'm
filing this bug report.

Bison-generated parsers currently contain code that GCC incorrectly
generates a -Wuninitialized warning for.  In trying to fix this, I
discovered that GCC sometimes does not warn when it should.  Compile
the following program with 'gcc -O2 -Wall -S'.

   union YYSTYPE { int ival; };
   union YYSTYPE
   yyparse (void)
   {
     union YYSTYPE yylval;
     return yylval;
   }


   struct s { int ival; };
   struct s
   yyparse_with_struct (void)
   {
     struct s xxlval;
     return xxlval;
   }

Here's what I observe, for the above program:

$ gcc -O2 -Wall -S t.i
t.i: In function 'yyparse_with_struct':
t.i:15:6: warning: 'xxlval.ival' is used uninitialized in this function
[-Wuninitialized]

There should be a warning for yylval, but the warning is missing.
The (correct) warning for xxlval suggests that the problem has
to do with unions, not structs.


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

* [Bug middle-end/54804] -Wuninitialized fails to warn about uninitialized local union
  2012-10-04  0:28 [Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union eggert at gnu dot org
@ 2012-10-04  8:07 ` manu at gcc dot gnu.org
  2021-03-25 23:13 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-04  8:07 UTC (permalink / raw)
  To: gcc-bugs


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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-04
                 CC|                            |manu at gcc dot gnu.org
          Component|c                           |middle-end
             Blocks|                            |24639
     Ever Confirmed|0                           |1

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-04 08:07:35 UTC ---
Confirmed. early SRA creates a scalar replacement for the struct but not for
the union:

;; Function yyparse (yyparse, funcdef_no=0, decl_uid=1710, cgraph_uid=0)
yyparse ()
{
  union YYSTYPE yylval;
  union YYSTYPE D.1720;

<bb 2>:
  [pr54804.c : 6:6] D.1720 = yylval;
  yylval ={v} {CLOBBER};
  [pr54804.c : 6:6] return D.1720;
}
;; Function yyparse_with_struct (yyparse_with_struct, funcdef_no=1,
decl_uid=1716, cgraph_uid=1)

Created a replacement for xxlval offset: 0, size: 32: xxlval$ival

Symbols to be put in SSA form
{ xxlval$ival }
Incremental SSA update started at block: 0
Number of blocks in CFG: 3
Number of blocks to update: 2 ( 67%)


yyparse_with_struct ()
{
  int xxlval$ival;
  struct s xxlval;
  struct s D.1723;

<bb 2>:
  [pr54804.c : 15:6] [pr54804.c : 15] MEM[(struct s *)&D.1723] =
xxlval$ival_3(D);
  [pr54804.c : 15:6] return D.1723;
}

Alternatively, one may see the problem as Wuninitialized not working with
anything that leaves in memory (structs/union/arrays) unless SRA is applied.
There are a few PRs about that.


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

* [Bug middle-end/54804] -Wuninitialized fails to warn about uninitialized local union
  2012-10-04  0:28 [Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union eggert at gnu dot org
  2012-10-04  8:07 ` [Bug middle-end/54804] " manu at gcc dot gnu.org
@ 2021-03-25 23:13 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-25 23:13 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 CC|                            |msebor at gcc dot gnu.org
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |7.0
           Keywords|                            |diagnostic

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 7 and later warn for both.  The change was introduced in r245840.

pr54804.c: In function ‘yyparse’:
pr54804.c:7:13: warning: ‘yylval’ is used uninitialized [-Wuninitialized]
    7 |      return yylval;
      |             ^~~~~~
pr54804.c:6:20: note: ‘yylval’ declared here
    6 |      union YYSTYPE yylval;
      |                    ^~~~~~
pr54804.c: In function ‘yyparse_with_struct’:
pr54804.c:16:13: warning: ‘xxlval’ is used uninitialized [-Wuninitialized]
   16 |      return xxlval;
      |             ^~~~~~
pr54804.c:15:15: note: ‘xxlval’ declared here
   15 |      struct s xxlval;
      |               ^~~~~~

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

end of thread, other threads:[~2021-03-25 23:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-04  0:28 [Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union eggert at gnu dot org
2012-10-04  8:07 ` [Bug middle-end/54804] " manu at gcc dot gnu.org
2021-03-25 23:13 ` msebor 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).