The following piece of code triggers a spurious warning when calling test_setjmpex() on GCC 12.3 and GCC 13.2 using -O2 or -O3. test.c: # compile with: gcc -c -O2 -Wuninitialized test.c int globalVar = 1; int __attribute__ ((__returns_twice__)) test_setjmpex(void *context); void testfn() { int localVar = globalVar; while (!localVar) { // The below triggers: // warning: '({anonymous})' is used uninitialized [-Wuninitialized] test_setjmpex(__builtin_frame_address (0)); if (globalVar) break; } } No includes needed, so I omitted the .i file. Initially setting tree-optimization as the component based on a guess. This was found when compiling Weiss (chess engine) for mingw, but the reduced test case triggers the warning on regular Linux, too. (Link to the original issue: https://github.com/TerjeKir/weiss/issues/680 ) Godbolt link: https://godbolt.org/z/ec1dKsx4q Experimentation with godbolt: - Affected GCC versions: 12.1 - 12.3; 13.1 - 13.2 ; multiple targets (at least: x86-64, aarch64, risc-v) - No warning on 11.x - No warning on trunk - No warning on -O1 Full repro: ----------- # Ubuntu 23.04 / x86_64-linux-gnu docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:13.2 gcc -v -c -O2 -Wuninitialized test.c Repro output: ------------- Using built-in specs. COLLECT_GCC=gcc Target: x86_64-linux-gnu Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++,fortran,go Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.3.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-c' '-O2' '-Wuninitialized' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc/x86_64-linux-gnu/12.3.0/cc1 -quiet -v -imultiarch x86_64-linux-gnu test.c -quiet -dumpbase test.c -dumpbase-ext .c -mtune=generic -march=x86-64 -O2 -Wuninitialized -version -o /tmp/ccZm0Pke.s GNU C17 (GCC) version 12.3.0 (x86_64-linux-gnu) compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/include /usr/local/include /usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C17 (GCC) version 12.3.0 (x86_64-linux-gnu) compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 1e1b4098557fa4aa478a5470075c20a5 test.c: In function 'testfn': test.c:12:11: warning: '({anonymous})' is used uninitialized [-Wuninitialized] 12 | test_setjmpex(__builtin_frame_address (0)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ COLLECT_GCC_OPTIONS='-v' '-c' '-O2' '-Wuninitialized' '-mtune=generic' '-march=x86-64' as -v --64 -o test.o /tmp/ccZm0Pke.s GNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.40 COMPILER_PATH=/usr/local/libexec/gcc/x86_64-linux-gnu/12.3.0/:/usr/local/libexec/gcc/x86_64-linux-gnu/12.3.0/:/usr/local/libexec/gcc/x86_64-linux-gnu/:/usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/:/usr/local/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/:/usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/usr/local/lib/gcc/x86_64-linux-gnu/12.3.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-c' '-O2' '-Wuninitialized' '-mtune=generic' '-march=x86-64'
Looks loop copy header change which allowed the warning not to happen. The warning is about the argument of test_setjmpex. Because GCC does not realize __builtin_frame_address cannot jump to the test_setjmpex ... In the case of GCC 12-13, the copy of the loop header happens during thread-full rather than earlier and inserts: _4(ab) = _11(D); Which is what is warned about. _11(D) does not get proped into the phi ...
(In reply to Andrew Pinski from comment #1) > Looks loop copy header change which allowed the warning not to happen. > > The warning is about the argument of test_setjmpex. Because GCC does not > realize __builtin_frame_address cannot jump to the test_setjmpex ... > > In the case of GCC 12-13, the copy of the loop header happens during > thread-full rather than earlier and inserts: > _4(ab) = _11(D); > > Which is what is warned about. > _11(D) does not get proped into the phi ... We can't propagate because /* Similarly if DEST flows in from an abnormal edge then the copy cannot be propagated. If we know we do not propagate into a PHI argument this does not apply. */ else if (!dest_not_phi_arg_p && TREE_CODE (dest) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)) return false; that's still not fine-grained enough - the case we cannot propagate is when we propagate into a PHI argument for an abnormal edge. The diagnostic doesn't happen on trunk, I still have a patch doing the propagation.
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:92ea12ea99fce546772a40b7bbc2ea850db9b1be commit r14-3916-g92ea12ea99fce546772a40b7bbc2ea850db9b1be Author: Richard Biener <rguenther@suse.de> Date: Wed Sep 13 09:28:34 2023 +0200 tree-optimization/111397 - missed copy propagation involving abnormal dest The following extends the previous enhancement to copy propagation involving abnormals. We can easily replace abnormal uses by not abnormal uses and only need to preserve the abnormals in PHI arguments flowing in from abnormal edges. This changes the may_propagate_copy argument indicating we are not propagating into a PHI node to indicate whether we know we are not propagating into a PHI argument from an abnormal PHI instead. PR tree-optimization/111397 * tree-ssa-propagate.cc (may_propagate_copy): Change optional argument to specify whether the PHI destination doesn't flow in from an abnormal PHI. (propagate_value): Adjust. * tree-ssa-forwprop.cc (pass_forwprop::execute): Indicate abnormal PHI dest. * tree-ssa-sccvn.cc (eliminate_dom_walker::before_dom_children): Likewise. (process_bb): Likewise. * gcc.dg/uninit-pr111397.c: New testcase.
Fixed on trunk, I know it works on the 13 branch, eventually will backport.
The releases/gcc-13 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:049ec9b981d1f4f97736061d5cf7d0ae990b57d7 commit r13-8037-g049ec9b981d1f4f97736061d5cf7d0ae990b57d7 Author: Richard Biener <rguenther@suse.de> Date: Wed Sep 13 09:28:34 2023 +0200 tree-optimization/111397 - missed copy propagation involving abnormal dest The following extends the previous enhancement to copy propagation involving abnormals. We can easily replace abnormal uses by not abnormal uses and only need to preserve the abnormals in PHI arguments flowing in from abnormal edges. This changes the may_propagate_copy argument indicating we are not propagating into a PHI node to indicate whether we know we are not propagating into a PHI argument from an abnormal PHI instead. PR tree-optimization/111397 * tree-ssa-propagate.cc (may_propagate_copy): Change optional argument to specify whether the PHI destination doesn't flow in from an abnormal PHI. (propagate_value): Adjust. * tree-ssa-forwprop.cc (pass_forwprop::execute): Indicate abnormal PHI dest. * tree-ssa-sccvn.cc (eliminate_dom_walker::before_dom_children): Likewise. (process_bb): Likewise. * gcc.dg/uninit-pr111397.c: New testcase. (cherry picked from commit 92ea12ea99fce546772a40b7bbc2ea850db9b1be)
GCC 12.4 is being released, retargeting bugs to GCC 12.5.