[Bug middle-end/97353] -Wuninitialized should warn about reading condition in do-loop

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

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org
   Severity|normal  |enhancement
 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=18501
   Last reconfirmed||2021-04-12
 Blocks||24639

--- Comment #2 from Martin Sebor  ---
With -O2 the function is optimized to a return statement before the late
warning runs so there's nothing to do there.

With -O1 the uninitialized variable is optimized out in CCP3 so there's nothing
to warn about either.

With -O0 the uninitialized read is unconditional in bb 3 in the IL below but
the warning doesn't analyze PHIs at that level so the bug isn't detected. 
Running the PHI analysis early (at -O0) would solve a whole class of false
negatives.  If done indiscriminately, it would also introduce a ton of false
positives unless perhaps the warning ran CCP first (without actually changing
the CFG).  A discussion of these problems is in pr18501.  Without the help of
CCP the early warning could also trigger for unconditionally reachable PHI
reads like the one in the test case.  So with that, let me confirm this
request. (The test case is too contrived to be worth worrying about on its own
since the loop doesn't do anything and can be optimized away regardless of
whether ok is initialized.  But it may be representative of similar but less
contrived cases where the early warning could expose a real bug).

int main ()
{
  int n;
  int ok;
  int D.1952;
  _Bool _1;
  int _9;

   :
  n_5 = 0;

   :
  # ok_2 = PHI 
  # n_4 = PHI 
  n_7 = n_4 + 1;
  if (n_7 == 1)
goto ; [INV]
  else
goto ; [INV]

   :
  // predicted unlikely by continue predictor.
  goto ; [INV]

   :
  _1 = n_7 > 1;
  ok_8 = (int) _1;

   :
  # ok_3 = PHI 
  if (ok_3 == 0)
goto ; [INV]
  else
goto ; [INV]

   :
  _9 = 0;

   :
:
  # VUSE <.MEM_10(D)>
  return _9;

}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

[Bug middle-end/97353] -Wuninitialized should warn about reading condition in do-loop

2020-10-12 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97353

Richard Biener  changed:

   What|Removed |Added

   Keywords||diagnostic

--- Comment #1 from Richard Biener  ---
We're likely threading this away before the late diagnostic.