public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
@ 2023-09-12 20:31 skiminki at gmail dot com
  2023-09-12 21:15 ` [Bug tree-optimization/111397] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: skiminki at gmail dot com @ 2023-09-12 20:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

            Bug ID: 111397
           Summary: Spurious warning "'({anonymous})' is used
                    uninitialized" when calling a __returns_twice__
                    function (-Wuninitialized -O2)
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: skiminki at gmail dot com
  Target Milestone: ---

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'

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
@ 2023-09-12 21:15 ` pinskia at gcc dot gnu.org
  2023-09-13  7:28 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12 21:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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 ...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
  2023-09-12 21:15 ` [Bug tree-optimization/111397] " pinskia at gcc dot gnu.org
@ 2023-09-13  7:28 ` rguenth at gcc dot gnu.org
  2023-09-13  8:22 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-13  7:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
   Last reconfirmed|                            |2023-09-13
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
(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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
  2023-09-12 21:15 ` [Bug tree-optimization/111397] " pinskia at gcc dot gnu.org
  2023-09-13  7:28 ` rguenth at gcc dot gnu.org
@ 2023-09-13  8:22 ` cvs-commit at gcc dot gnu.org
  2023-09-13  8:25 ` [Bug tree-optimization/111397] [12/13 Regression] " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-13  8:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] [12/13 Regression] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
                   ` (2 preceding siblings ...)
  2023-09-13  8:22 ` cvs-commit at gcc dot gnu.org
@ 2023-09-13  8:25 ` rguenth at gcc dot gnu.org
  2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
  2024-06-20  9:13 ` [Bug tree-optimization/111397] [12 " rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-13  8:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |12.3.1, 13.2.1
            Summary|Spurious warning            |[12/13 Regression] Spurious
                   |"'({anonymous})' is used    |warning "'({anonymous})' is
                   |uninitialized" when calling |used uninitialized" when
                   |a __returns_twice__         |calling a __returns_twice__
                   |function (-Wuninitialized   |function (-Wuninitialized
                   |-O2)                        |-O2)
           Priority|P3                          |P2
   Target Milestone|---                         |12.4
             Blocks|                            |24639
      Known to work|                            |11.4.1, 14.0

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk, I know it works on the 13 branch, eventually will backport.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] [12/13 Regression] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
                   ` (3 preceding siblings ...)
  2023-09-13  8:25 ` [Bug tree-optimization/111397] [12/13 Regression] " rguenth at gcc dot gnu.org
@ 2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
  2024-06-20  9:13 ` [Bug tree-optimization/111397] [12 " rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-10 14:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/111397] [12 Regression] Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2)
  2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
                   ` (4 preceding siblings ...)
  2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
@ 2024-06-20  9:13 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-20  9:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111397

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.4                        |12.5

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.4 is being released, retargeting bugs to GCC 12.5.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-20  9:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 20:31 [Bug tree-optimization/111397] New: Spurious warning "'({anonymous})' is used uninitialized" when calling a __returns_twice__ function (-Wuninitialized -O2) skiminki at gmail dot com
2023-09-12 21:15 ` [Bug tree-optimization/111397] " pinskia at gcc dot gnu.org
2023-09-13  7:28 ` rguenth at gcc dot gnu.org
2023-09-13  8:22 ` cvs-commit at gcc dot gnu.org
2023-09-13  8:25 ` [Bug tree-optimization/111397] [12/13 Regression] " rguenth at gcc dot gnu.org
2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
2024-06-20  9:13 ` [Bug tree-optimization/111397] [12 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).