public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kamilcukrowski at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/105331] New: -Wmaybe-uninitialized warning on va_arg with double _Complex on va_list pointer
Date: Thu, 21 Apr 2022 08:46:07 +0000	[thread overview]
Message-ID: <bug-105331-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-04-21  8:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21  8:46 kamilcukrowski at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105331-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).