https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84604
Bug ID: 84604 Summary: False positive "may be used uninitialized in this function" due to variable initialization eliminated as dead code Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cas43 at cs dot stanford.edu Target Milestone: --- WHAT HAPPENS: The compiler eliminates a=0; and b=0; from the code below during the dce2 optimization pass, resulting in a warning for use of uninitialized variable. Curiously, the generate code seems to be okay. OFFENDING CODE: void f(); struct S { int a; int b; S() { a=0; b=0; } ~S() { } void g(int) { if(a<10) { f(); for(int i=0;i<b;i++){} this->~S(); a=b+2; } } }; int foo() { S s; s.g(0); s.g(0); return s.a+s.b; } OPTIMIZED RESULT: (via -fdump-tree-all) ;; Function foo (_Z3foov, funcdef_no=7, decl_uid=2398, cgraph_uid=7, symbol_order=7) foo () { int s$b; int _5; int _16; <bb 2> [local count: 1073741825]: f (); _16 = s$b_12(D) + 2; if (_16 <= 9) goto <bb 4>; [33.00%] else goto <bb 3>; [67.00%] <bb 3> [local count: 1073741827]: _5 = s$b_12(D) + _16; return _5; <bb 4> [local count: 354334802]: f (); goto <bb 3>; [100.00%] } GENERATED ASM: .file "prog.cpp" .text .p2align 4,,15 .globl _Z3foov .type _Z3foov, @function _Z3foov: .LFB7: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 call _Z1fv call _Z1fv movl $2, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE7: .size _Z3foov, .-_Z3foov .ident "GCC: (GNU) 8.0.1 20180227 (experimental)" .section .note.GNU-stack,"",@progbits COMPILER VERSION: Using built-in specs. COLLECT_GCC=/home/craig/new-gcc/i-trunk/bin/g++ COLLECT_LTO_WRAPPER=/home/craig/new-gcc/i-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../s-trunk/configure --prefix=/home/craig/new-gcc/i-trunk --disable-multilib Thread model: posix gcc version 8.0.1 20180227 (experimental) (GCC) COMPILATION FLAGS: g++ prog.cpp -Wall -c -O2 OTHER VERSIONS that give false positev: 4.9.3 (Ubuntu 4.9.3-13ubuntu2) 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)