https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90994
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2021-04-07 Known to fail| |10.2.0, 11.0, 9.2.0 CC| |msebor at gcc dot gnu.org --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. The warning sees the IL below. The reason for the false positive is the assignment in bb 5 marked not handled. The warning walks up the control flow graph from the point of the possibly uninitialized use to the definition of the a_33 variable (a PHI), looking for predicates that guard it to try to determine if they are mutually exclusive with those guarding the uninitialized operand to the PHI. It recongnizes conditional expressions and switch statements but nothing else (such the assignment here). As a result, the logic fails to detect that the conditionals prevent the uninitialized variable from being used. int incorrectWarning () { int D.2387; int D.2383; unsigned char b; unsigned char a; int _3; int _5; int _6; bool prephitmp_10; unsigned char _17; int _18; void * _19; unsigned char _20; void * _22; <bb 2> [local count: 1073741824]: # VUSE <.MEM_8(D)> _17 ={v} MEM[(volatile unsigned char *)1234B]; <bb 9> [local count: 1073741824]: <bb 3> [local count: 1073741824]: # _18 = PHI <0(9), -1(4)> <<< _18 != 0 in bb 4 # .MEM_23 = PHI <.MEM_8(D)(9), .MEM_26(4)> # a_33 = PHI <_17(9), a_35(D)(4)> <<< a_33 uninitialized if _18 != 0 # prephitmp_10 = PHI <0(9), 1(4)> __asm__ __volatile__(" " : : "X" prephitmp_10); if (_18 != 0) goto <bb 10>; [51.12%] else goto <bb 5>; [48.88%] <<< _18 == 0 implies a_33 = _17(9) <bb 10> [local count: 548896824]: goto <bb 8>; [100.00%] <bb 4> [count: 0]: <L8>: # VUSE <.MEM_8(D)> _19 = __builtin_eh_pointer (3); # .MEM_25 = VDEF <.MEM_8(D)> __cxa_begin_catch (_19); # .MEM_26 = VDEF <.MEM_25> __cxa_end_catch (); goto <bb 3>; [0.00%] <bb 5> [local count: 524845000]: # VUSE <.MEM_23> _20 ={v} MEM[(volatile unsigned char *)1234B]; <<< not handled <bb 6> [local count: 524845000]: _3 = (int) a_33; <<< -Wmaybe-uninitialized # .MEM_13 = VDEF <.MEM_23> printval (_3); _5 = (int) _20; # .MEM_14 = VDEF <.MEM_13> printval (_5); goto <bb 8>; [100.00%] <bb 7> [count: 0]: <L10>: # VUSE <.MEM_23> _22 = __builtin_eh_pointer (4); # .MEM_29 = VDEF <.MEM_23> __cxa_begin_catch (_22); # .MEM_30 = VDEF <.MEM_29> __cxa_end_catch (); <bb 8> [local count: 1073741824]: # _6 = PHI <0(6), 1(7), 1(10)> # .MEM_7 = PHI <.MEM_14(6), .MEM_30(7), .MEM_23(10)> # VUSE <.MEM_7> return _6; }