https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83382
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 Known to fail| |10.2.0, 11.0, 8.3.0, 9.3.0 Status|UNCONFIRMED |NEW Last reconfirmed| |2021-04-06 --- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> --- Reconfirmed with GCC 11. The warning sees the IL below and triggers for the call to .UBSAN_NULL() after the CFG pass has removed the initialization of p.1. A simple way to avoid it is to suppress warnings for calls to the sanitizer internal functions. Interestingly, this bug is only reproducible with C++, not when the same code is compiled as C. $ gcc -O0 -S -Wall -fsanitize=undefined -fdump-tree-cfg-details=/dev/stdout -xc++ pr83382.c pr83382.c: In function ‘void f()’: pr83382.c:6:5: warning: value computed is not used [-Wunused-value] 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function f (_Z1fv, funcdef_no=0, decl_uid=2788, cgraph_uid=1, symbol_order=5) Scope blocks: { Scope block #0 } Removing basic block 3 ;; basic block 3, loop depth 0 ;; pred: p.1 = p; <<< initialization removed .UBSAN_NULL (p.1, 2B, 4); _1 = MEM[(const int &)p.1]; _2 = _1 != 0; _3 = (int) _2; _4 = (unsigned long) _3; _5 = (unsigned long) i.0; __builtin___ubsan_handle_shift_out_of_bounds (&*.Lubsan_data0, _5, _4); ;; succ: 4 ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 ;; 2 succs { 3 } ;; 3 succs { 1 } void f () { int * p.1; <<< not initialized int i.0; <bb 2> : i.0 = i; <bb 3> : .UBSAN_NULL (p.1, 2B, 4); <<< -Wuninitialized _6 = MEM[(const int &)p.1]; _7 = _6 != 0; _8 = (int) _7; return; } pr83382.c:6:25: warning: ‘p.1’ is used uninitialized [-Wuninitialized] 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~~^~~~~~~~~ pr83382.c:6:25: note: ‘p.1’ was declared here 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~~^~~~~~~~~