public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning
       [not found] <bug-85301-4@http.gcc.gnu.org/bugzilla/>
@ 2021-04-05 20:34 ` msebor at gcc dot gnu.org
  2022-11-20  4:17 ` law at gcc dot gnu.org
  2022-11-28 22:36 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2018-04-09 00:00:00         |2021-4-5
      Known to fail|                            |10.2.0, 11.0, 8.3.0, 9.3.0
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99919
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11 with the ever-so-slightly slightly simplified program
below and enhanced output.  The warning has been issued since at least GCC 4.1
and so is not a regression.

$ cat pr85301.c && gcc -O2 -S -Wall -DUSE_BITFIELD  pr85301.c
struct A
{
#ifdef USE_BITFIELD
  unsigned i : 1;
  unsigned j : 1;
#else
  unsigned i;
  unsigned j;
#endif
};

int z, f (void);

struct A a;

void h (void)
{
  int y;

  if (a.j || a.i)
    y = f ();

  if (a.i)
    z = y;
}

pr85301.c: In function ‘h’:
pr85301.c:24:7: warning: ‘y’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   24 |     z = y;
      |     ~~^~~
pr85301.c:18:7: note: when ‘!(((unsigned char*)&a)[0] & 3)’
   18 |   int y;
      |       ^
pr85301.c:18:7: note: used when ‘prephitmp_15 = PHI <_1(7), pretmp_14(3)> & 1’
pr85301.c:18:7: note: ‘y’ was declared here

Jump threading and other optimization opportunities aside (I have raised
pr99918 for one of those), there does also seem to be a limitation in the
warning code in that it doesn't understand BIT_FIELD_REF expressions.  The
warning sees the IL below from which it should be able to determine that y's
use is conditional on its definition (i.e., the use predicate a strict subset
of the predicate controlling the definition).

void h ()
{
  int y;
  unsigned char _1;
  unsigned char _2;
  unsigned char _4;
  unsigned char pretmp_14;
  unsigned char prephitmp_15;

  <bb 2> [local count: 1073741824]:
  # VUSE <.MEM_8(D)>
  _1 = BIT_FIELD_REF <a, 8, 0>;
  _2 = _1 & 3;
  if (_2 != 0)
    goto <bb 3>; [33.00%]
  else
    goto <bb 7>; [67.00%]

  <bb 7> [local count: 719407024]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 354334800]:
  # .MEM_10 = VDEF <.MEM_8(D)>
  y_11 = f ();
  # VUSE <.MEM_10>
  pretmp_14 = BIT_FIELD_REF <a, 8, 0>;

  <bb 4> [local count: 1073741824]:
  # y_5 = PHI <y_9(D)(7), y_11(3)>
  # .MEM_6 = PHI <.MEM_8(D)(7), .MEM_10(3)>
  # prephitmp_15 = PHI <_1(7), pretmp_14(3)>
  _4 = prephitmp_15 & 1;
  if (_4 != 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 8>; [50.00%]

  <bb 8> [local count: 536870912]:
  goto <bb 6>; [100.00%]

  <bb 5> [local count: 536870913]:
  ## y_5 = PHI <y_9(D)(7), y_11(3)>
  ## uninit when: _2 == 0
  ##            : BIT_FIELD_REF <a, 8, 0> & 3 == 0
  ##
  ## used when: prephitmp_15 & != 0
  ##          : PHI <_1(7), pretmp_14(3)>
  ##          : _1(7) != 0 || pretmp_14 != 0
  ##          : BIT_FIELD_REF <a, 8, 0> != 0 || BIT_FIELD_REF <a, 8, 0> != 0
  ##          : BIT_FIELD_REF <a, 8, 0> != 0
  # .MEM_12 = VDEF <.MEM_6>
  z = y_5;

  <bb 6> [local count: 1073741824]:
  # .MEM_7 = PHI <.MEM_6(8), .MEM_12(5)>
  # VUSE <.MEM_7>
  return;

}

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

* [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning
       [not found] <bug-85301-4@http.gcc.gnu.org/bugzilla/>
  2021-04-05 20:34 ` [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning msebor at gcc dot gnu.org
@ 2022-11-20  4:17 ` law at gcc dot gnu.org
  2022-11-28 22:36 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: law at gcc dot gnu.org @ 2022-11-20  4:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Jeffrey A. Law <law at gcc dot gnu.org> ---
This has been fixed on the trunk.

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

* [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning
       [not found] <bug-85301-4@http.gcc.gnu.org/bugzilla/>
  2021-04-05 20:34 ` [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning msebor at gcc dot gnu.org
  2022-11-20  4:17 ` law at gcc dot gnu.org
@ 2022-11-28 22:36 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-28 22:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0

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

end of thread, other threads:[~2022-11-28 22:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-85301-4@http.gcc.gnu.org/bugzilla/>
2021-04-05 20:34 ` [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning msebor at gcc dot gnu.org
2022-11-20  4:17 ` law at gcc dot gnu.org
2022-11-28 22:36 ` pinskia 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).