tree-optimization/101573 - improve uninit warning at -O0
authorRichard Biener <rguenther@suse.de>
Thu, 22 Jul 2021 10:26:16 +0000 (12:26 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 27 Jul 2021 08:46:22 +0000 (10:46 +0200)
commit66030d68a7edfc9504a50469598e0707b8f787ce
treea005e80a5eacf12378a75971b856ed6c0d9771a7
parentc8ce54c6e67295b70052d1b9f9a2f7ce9e2f8f0d
tree-optimization/101573 - improve uninit warning at -O0

We can improve uninit warnings from the early pass by looking
at PHI arguments on fallthru edges that are uninitialized and
have uses that are before a possible loop exit.  This catches
some cases earlier that we'd only warn in a more confusing
way after early inlining as seen by testcase adjustments.

It introduces

FAIL: gcc.dg/uninit-23.c (test for excess errors)

where we additionally warn

gcc.dg/uninit-23.c:21:13: warning: 't4' is used uninitialized [-Wuninitialized]

which I think is OK even if it's not obvious that the new
warning is an improvement when you look at the obvious source.

Somehow for all cases I never get the `'foo' was declared here`
notes, I didn't dig why that happens but it's odd.

2021-07-22  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101573
* tree-ssa-uninit.c (warn_uninit_phi_uses): New function
looking at uninitialized PHI arg defs in some constrained cases.
(warn_uninitialized_vars): Call it.
(execute_early_warn_uninitialized): Calculate dominators.

* gcc.dg/uninit-pr101573.c: New testcase.
* gcc.dg/uninit-15-O0.c: Adjust.
* gcc.dg/uninit-15.c: Likewise.
* gcc.dg/uninit-23.c: Likewise.
* c-c++-common/uninit-17.c: Likewise.
gcc/testsuite/c-c++-common/uninit-17.c
gcc/testsuite/gcc.dg/uninit-15-O0.c
gcc/testsuite/gcc.dg/uninit-15.c
gcc/testsuite/gcc.dg/uninit-23.c
gcc/testsuite/gcc.dg/uninit-pr101573.c [new file with mode: 0644]
gcc/tree-ssa-uninit.c