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

Martin Sebor <msebor at gcc dot gnu.org> 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 <msebor at gcc dot gnu.org> ---
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;

  <bb 2> [local count: 1073741824]:
  if (x_4(D) == 2)
    goto <bb 5>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 5> [local count: 365072224]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 708669600]:

  <bb 4> [local count: 1073741824]:
  # p_3 = PHI <&a(3), &b(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;

  <bb 2> :
  if (x_5(D) == 1)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  p_7 = &a;

  <bb 4> :
  # p_3 = PHI <p_6(D)(2), p_7(3)>
  if (x_5(D) == 2)
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 5> :
  p_8 = &b;

  <bb 6> :
  # p_4 = PHI <p_3(4), p_8(5)>
  # 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;

}

Reply via email to