[Bug middle-end/93181] [9/10/11 Regression] -Wuninitialized fails to warn about uninitialized value

2021-04-08 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93181

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |9.4

[Bug middle-end/93181] [9/10/11 Regression] -Wuninitialized fails to warn about uninitialized value

2021-04-07 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93181

Martin Sebor  changed:

   What|Removed |Added

Summary|-Wuninitialized fails to|[9/10/11 Regression]
   |warn about uninitialized|-Wuninitialized fails to
   |value;  |warn about uninitialized
   |-Wmaybe-uninitialized   |value
   |should also warn.   |
 CC||msebor at gcc dot gnu.org
   Last reconfirmed|2020-01-21 00:00:00 |2021-4-7
  Known to fail||10.2.0, 11.0, 9.2.0

--- Comment #2 from Martin Sebor  ---
Reconfirmed with GCC 11.  The warning ceased to be issued between r120372 and
r120373 so it's technically a regression.

With optimization the warning sees the IL below.  Both arguments of the p_3 PHI
that it considers are valid so it has nothing to complain about.

void ub_express (int x)
{
  struct foo * p;
  int _1;
  int _2;

   [local count: 1073741824]:
  if (x_4(D) == 2)
goto ; [34.00%]
  else
goto ; [66.00%]

   [local count: 365072224]:
  goto ; [100.00%]

   [local count: 708669600]:

   [local count: 1073741824]:
  # p_3 = PHI <(3), (5)>
  # VUSE <.MEM_6(D)>
  _1 = p_3->count;
  _2 = _1 + 1;
  # .MEM_7 = VDEF <.MEM_6(D)>
  p_3->count = _2;
  # VUSE <.MEM_7>
  return;

}

Without optimization the IL (below) does have a PHI with an uninitialized
operand so it could warn then, but it doesn't consider PHI nodes then. 
Considering PHIs in the simplest cases (to avoid false positives) also when
-Wuninitialized runs early, without optimization, would make it possible to
detect this bug.

void ub_express (int x)
{
  struct foo * p;
  int _1;
  int _2;

   :
  if (x_5(D) == 1)
goto ; [INV]
  else
goto ; [INV]

   :
  p_7 = 

   :
  # p_3 = PHI 
  if (x_5(D) == 2)
goto ; [INV]
  else
goto ; [INV]

   :
  p_8 = 

   :
  # p_4 = PHI 
  # VUSE <.MEM_9(D)>
  _1 = p_4->count;
  _2 = _1 + 1;
  # .MEM_10 = VDEF <.MEM_9(D)>
  p_4->count = _2;
  # VUSE <.MEM_10>
  return;

}