https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57832
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2018-10-09 00:00:00 |2021-3-26
Known to fail| |10.2.0, 11.0, 4.8.4, 4.9.4,
| |5.5.0, 6.4.0, 7.2.0, 8.3.0,
| |9.1.0
CC| |msebor at gcc dot gnu.org
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11 and a slightly further reduced test case:
int a, b, d;
void f (void)
{
unsigned c;
for (int e = 0; e < 64; e += 6)
{
if (e)
b = e;
else
c = d;
if (e)
a += c;
}
}
The output with a slightly patched GCC to add notes after the warning shows the
condition under which the variable is used uninitialized:
pr57832.c: In function ‘f’:
pr57832.c:15:11: warning: ‘c’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
15 | a += c;
| ^~
pr57832.c:5:12: note: used when ‘ivtmp != 0’
5 | unsigned c;
| ^
pr57832.c:5:12: note: ‘c’ was declared here
The annotated dump below helps explain what's going on: the c_21 PHI in bb 3 is
(partly) uninitialized. The warning finds its first use (1) in c_21 in bb 3.
It then finds its use (2) in c_25 in bb 5. Finally, it finds c_25's use (3) in
the assignment to _4 in bb 4. In other words, the uninitialized c flows from
<bb 2: c_12(D)> -> <bb 3: c_21> -> <bb 8> -> <bb 5: c25> -> <bb 3: c_21> -> <bb
4: _4>. I don't see anything in the IL to avoid coming to this conclusion so I
don't think there's anything to change in the warning code to suppress it.
;; Function f (f, funcdef_no=0, decl_uid=1946, cgraph_uid=1, symbol_order=3)
[WORKLIST]: add to initial list: c_21 = PHI <c_25(5), c_12(D)(2)>
[CHECK]: examining phi: c_21 = PHI <c_25(5), c_12(D)(2)>
[CHECK] Found def edge 1 in c_25 = PHI <c_21(8), c_14(7)>
[CHECK]: Found unguarded use: c_25 = PHI <c_21(8), c_14(7)>
[WORKLIST]: Update worklist with phi: c_25 = PHI <c_21(8), c_14(7)>
[CHECK] Found def edge 1 in c_25 = PHI <c_21(8), c_14(7)>
[CHECK]: Found unguarded use: _4 = a.2_3 + c_21;
{
unsigned int ivtmp.11;
unsigned int ivtmp.10;
int a_lsm.7;
int b_lsm.6;
int e;
unsigned int c;
int d.0_1;
unsigned int a.2_3;
unsigned int _4;
int _5;
<bb 2> [local count: 89442694]:
d.0_1 = d;
c_14 = (unsigned int) d.0_1;
a_lsm.7_18 = a;
<bb 3> [local count: 984299128]:
# c_21 = PHI <c_25(5), c_12(D)(2)> <<< use 1: c_12(D) is
uninitialized
# a_lsm.7_11 = PHI <a_lsm.7_10(5), a_lsm.7_18(2)>
# ivtmp.10_2 = PHI <ivtmp.10_7(5), 0(2)>
# ivtmp.11_20 = PHI <ivtmp.11_26(5), 6(2)>
e_22 = (int) ivtmp.10_2;
if (e_22 != 0)
goto <bb 4>; [64.00%]
else
goto <bb 7>; [36.00%]
<bb 7> [local count: 354347685]:
goto <bb 5>; [100.00%]
<bb 4> [local count: 629951444]:
a.2_3 = (unsigned int) a_lsm.7_11;
_4 = a.2_3 + c_21; <<< use 3:
-Wmaybe-uninitialized
_5 = (int) _4;
e_17 = (int) ivtmp.11_20;
if (e_17 <= 63)
goto <bb 8>; [86.98%]
else
goto <bb 6>; [13.02%]
<bb 8> [local count: 547959327]: <<< c_21(8) = c21(3)
<bb 5> [local count: 902307011]:
# c_25 = PHI <c_21(8), c_14(7)> <<< use 2: c_25 =
c_21(8)
# a_lsm.7_10 = PHI <_5(8), a_lsm.7_11(7)>
ivtmp.10_7 = ivtmp.10_2 + 6;
ivtmp.11_26 = ivtmp.11_20 + 6;
goto <bb 3>; [100.00%]
<bb 6> [local count: 89442696]:
b = e_22;
a = _5;
return;
}