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