https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89697
Bug ID: 89697
Summary: SRA prevents -Wuninitialized warning
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
For
struct my_struct {
int i1;
int i2;
};
static struct my_struct s1;
void
wtest(void)
{
struct my_struct s2; /* not initialized */
if (s1.i1 == 0) {
s1 = s2; /* assigning uninitialized variable */
}
}
without SRA, thus -O0 or -On with -fno-tree-sra reports:
t.c: In function ‘wtest’:
t.c:13:10: warning: ‘s2’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
13 | s1 = s2; /* assigning uninitialized variable */
| ~~~^~~~
but when SRA is enabled we get no warning. This is even though the
uninitialized use is clearly visible in the IL:
wtest ()
{
int s2$i2;
int s2$i1;
int _1;
<bb 2> [local count: 1073741824]:
_1 = s1.i1;
if (_1 == 0)
goto <bb 3>; [50.00%]
else
goto <bb 5>; [50.00%]
<bb 5> [local count: 536870912]:
goto <bb 4>; [100.00%]
<bb 3> [local count: 536870913]:
MEM[(struct my_struct *)&s1] = s2$i1_4(D);
MEM[(struct my_struct *)&s1 + 4B] = s2$i2_6(D);
<bb 4> [local count: 1073741824]:
return;
}