public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
@ 2022-04-21  8:46 kamilcukrowski at gmail dot com
  2022-04-21  9:03 ` [Bug middle-end/105331] [11/12 Regression] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: kamilcukrowski at gmail dot com @ 2022-04-21  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105331
           Summary: -Wmaybe-uninitialized warning on va_arg with double
                    _Complex on va_list pointer
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kamilcukrowski at gmail dot com
  Target Milestone: ---

Passing a pointer to `va_list` to a function, and then using `va_arg` with type
`double _Complex` with derefenced pointer to `va_list` results in a false
positive `-Wmaybe-uninitailized` warning. It is a false-positive - it's a
pointer to `va_list`, the pointed-to value is just initialized by the caller.

Note that this triggers _only_ with `double _Complex` type. Neither `long
double _Complex` or `float _Complex` or `double` or any other type.

> the exact version of GCC; the options given when GCC was configured/built;

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-linker-build-id --enable-lto
--enable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
--with-build-config=bootstrap-lto --enable-link-serialization=1
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC) 

> the system type;

$ uname -a
Linux leonidas 5.17.1-zen1-1-zen #1 ZEN SMP PREEMPT Mon, 28 Mar 2022 21:56:46
+0000 x86_64 GNU/Linux
$ cat /etc/arch-release 
Arch Linux release

> the complete command line that triggers the bug; the compiler output (error messages, warnings, etc.); 

$ gcc --save-temps -O -Wmaybe-uninitialized -c example.c
example.c: In function ‘take_double_complex_to_int’:
example.c:4:38: warning: ‘va_arg_tmp.5’ may be used uninitialized
[-Wmaybe-uninitialized]
    4 |         return va_arg(*va, double _Complex);
      |                ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~         

> and the preprocessed file (*.i*) that triggers the bug

```
$ cat example.i 
# 0 "example.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "example.c"
typedef __builtin_va_list va_list;

int take_double_complex_to_int(va_list *va) {
 return __builtin_va_arg(*va, double _Complex);
}
```


--- Really, it's just:
$ cat example.c 
typedef __builtin_va_list va_list;
#define va_arg(ap, type)    __builtin_va_arg(ap, type)
int take_double_complex_to_int(va_list *va) {
        return va_arg(*va, double _Complex);
}


--- I tested docker containers: image gcc:10 works, but image gcc:11.1.0 shows
the error :

$ dockertest() { if docker run -i --rm $1 gcc -O -Wmaybe-uninitialized -Werror
-c -xc - < example.c; then echo "$1: FINE"; else echo "$1: error"; fi; }
$ dockertest gcc:10
gcc:10 FINE
$ dockertest gcc:11
<stdin>: In function 'take_double_complex_to_int':
<stdin>:4:21: error: 'va_arg_tmp.5' may be used uninitialized
[-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
gcc:11: error

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

* [Bug middle-end/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
@ 2022-04-21  9:03 ` jakub at gcc dot gnu.org
  2022-04-21  9:07 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-21  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Priority|P3                          |P2
     Ever confirmed|0                           |1
            Summary|-Wmaybe-uninitialized       |[11/12 Regression]
                   |warning on va_arg with      |-Wmaybe-uninitialized
                   |double _Complex on va_list  |warning on va_arg with
                   |pointer                     |double _Complex on va_list
                   |                            |pointer
   Last reconfirmed|                            |2022-04-21
          Component|c                           |middle-end
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |11.4

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r11-165-geb72dc663e9070b281be83a80f6f838a3a878822

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

* [Bug middle-end/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
  2022-04-21  9:03 ` [Bug middle-end/105331] [11/12 Regression] " jakub at gcc dot gnu.org
@ 2022-04-21  9:07 ` jakub at gcc dot gnu.org
  2022-04-21 10:17 ` [Bug target/105331] " jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-21  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug target/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
  2022-04-21  9:03 ` [Bug middle-end/105331] [11/12 Regression] " jakub at gcc dot gnu.org
  2022-04-21  9:07 ` jakub at gcc dot gnu.org
@ 2022-04-21 10:17 ` jakub at gcc dot gnu.org
  2022-04-21 11:03 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-21 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52844
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52844&action=edit
gcc12-pr105331.patch

Untested fix.

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

* [Bug target/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (2 preceding siblings ...)
  2022-04-21 10:17 ` [Bug target/105331] " jakub at gcc dot gnu.org
@ 2022-04-21 11:03 ` rguenth at gcc dot gnu.org
  2022-04-21 11:06 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
possibly other targets have copied the same pattern and thus have the same
issue (the varargs code tends to be cut&pasted)

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

* [Bug target/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (3 preceding siblings ...)
  2022-04-21 11:03 ` rguenth at gcc dot gnu.org
@ 2022-04-21 11:06 ` jakub at gcc dot gnu.org
  2022-04-28 10:35 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-21 11:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I actually went through them all and didn't see it elsewhere (was looking for
ADDR_EXPR word inside of *gimplify_va_arg*).

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

* [Bug target/105331] [11/12 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (4 preceding siblings ...)
  2022-04-21 11:06 ` jakub at gcc dot gnu.org
@ 2022-04-28 10:35 ` cvs-commit at gcc dot gnu.org
  2022-04-28 10:36 ` [Bug target/105331] [11 " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-28 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:89dbf9a5f55e0f7565865d1b38e681ef7d76afaf

commit r12-8301-g89dbf9a5f55e0f7565865d1b38e681ef7d76afaf
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 28 12:33:59 2022 +0200

    i386: Fix up ix86_gimplify_va_arg [PR105331]

    On the following testcase we emit a bogus
    'va_arg_tmp.5' may be used uninitialized
    warning.  The reason is that when gimplifying the addr = &temp;
    statement, the va_arg_tmp temporary var for which we emit ADDR_EXPR
    is not TREE_ADDRESSABLE, prepare_gimple_addressable emits some extra
    code to initialize the newly addressable var from its previous value,
    but it is a new variable which hasn't been initialized yet and will
    be later, so we end up initializing it with uninitialized SSA_NAME:
      va_arg_tmp.6 = va_arg_tmp.5_14(D);
      addr.2_16 = &va_arg_tmp.6;
      _17 = MEM[(double *)sse_addr.4_13];
      MEM[(double * {ref-all})addr.2_16] = _17;
    and with -O1 we actually don't DSE it before the warning is emitted.
    If we make the temp TREE_ADDRESSABLE before the gimplification, then
    this prepare_gimple_addressable path isn't taken and we effectively
    omit the first statement above and so the bogus warning is gone.

    I went through other backends and didn't find another instance of this
    problem.

    2022-04-28  Jakub Jelinek  <jakub@redhat.com>

            PR target/105331
            * config/i386/i386.cc (ix86_gimplify_va_arg): Mark va_arg_tmp
            temporary TREE_ADDRESSABLE before trying to gimplify ADDR_EXPR
            of it.

            * gcc.dg/pr105331.c: New test.

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

* [Bug target/105331] [11 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (5 preceding siblings ...)
  2022-04-28 10:35 ` cvs-commit at gcc dot gnu.org
@ 2022-04-28 10:36 ` jakub at gcc dot gnu.org
  2022-05-06 23:44 ` cvs-commit at gcc dot gnu.org
  2022-05-09 11:25 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-28 10:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 Regression]          |[11 Regression]
                   |-Wmaybe-uninitialized       |-Wmaybe-uninitialized
                   |warning on va_arg with      |warning on va_arg with
                   |double _Complex on va_list  |double _Complex on va_list
                   |pointer                     |pointer

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

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

* [Bug target/105331] [11 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (6 preceding siblings ...)
  2022-04-28 10:36 ` [Bug target/105331] [11 " jakub at gcc dot gnu.org
@ 2022-05-06 23:44 ` cvs-commit at gcc dot gnu.org
  2022-05-09 11:25 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-06 23:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:65c1c480b33ea36e9505ed444eed09a0cc1c9256

commit r11-9964-g65c1c480b33ea36e9505ed444eed09a0cc1c9256
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 28 12:33:59 2022 +0200

    i386: Fix up ix86_gimplify_va_arg [PR105331]

    On the following testcase we emit a bogus
    'va_arg_tmp.5' may be used uninitialized
    warning.  The reason is that when gimplifying the addr = &temp;
    statement, the va_arg_tmp temporary var for which we emit ADDR_EXPR
    is not TREE_ADDRESSABLE, prepare_gimple_addressable emits some extra
    code to initialize the newly addressable var from its previous value,
    but it is a new variable which hasn't been initialized yet and will
    be later, so we end up initializing it with uninitialized SSA_NAME:
      va_arg_tmp.6 = va_arg_tmp.5_14(D);
      addr.2_16 = &va_arg_tmp.6;
      _17 = MEM[(double *)sse_addr.4_13];
      MEM[(double * {ref-all})addr.2_16] = _17;
    and with -O1 we actually don't DSE it before the warning is emitted.
    If we make the temp TREE_ADDRESSABLE before the gimplification, then
    this prepare_gimple_addressable path isn't taken and we effectively
    omit the first statement above and so the bogus warning is gone.

    I went through other backends and didn't find another instance of this
    problem.

    2022-04-28  Jakub Jelinek  <jakub@redhat.com>

            PR target/105331
            * config/i386/i386.c (ix86_gimplify_va_arg): Mark va_arg_tmp
            temporary TREE_ADDRESSABLE before trying to gimplify ADDR_EXPR
            of it.

            * gcc.dg/pr105331.c: New test.

    (cherry picked from commit 89dbf9a5f55e0f7565865d1b38e681ef7d76afaf)

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

* [Bug target/105331] [11 Regression] -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
  2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
                   ` (7 preceding siblings ...)
  2022-05-06 23:44 ` cvs-commit at gcc dot gnu.org
@ 2022-05-09 11:25 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-09 11:25 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-05-09 11:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21  8:46 [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer kamilcukrowski at gmail dot com
2022-04-21  9:03 ` [Bug middle-end/105331] [11/12 Regression] " jakub at gcc dot gnu.org
2022-04-21  9:07 ` jakub at gcc dot gnu.org
2022-04-21 10:17 ` [Bug target/105331] " jakub at gcc dot gnu.org
2022-04-21 11:03 ` rguenth at gcc dot gnu.org
2022-04-21 11:06 ` jakub at gcc dot gnu.org
2022-04-28 10:35 ` cvs-commit at gcc dot gnu.org
2022-04-28 10:36 ` [Bug target/105331] [11 " jakub at gcc dot gnu.org
2022-05-06 23:44 ` cvs-commit at gcc dot gnu.org
2022-05-09 11:25 ` jakub 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).