Hello, the following source file (here called `gcc_bug.c') triggers
`-Wmaybe-uninitialized' when compiled with `-Os', `-O1' or stronger
optimisation, plus `-Wall':
#include
#include
static int mk (int **a, int **b, int **c) {
if (!(*a = malloc (sizeof (int goto a_err;
if (!(*b = malloc (sizeof (int goto b_err;
if (!(*c = malloc (sizeof (int goto c_err;
return 1; c_err:
free (*b); b_err:
free (*a); a_err:
return 0;
}
static void fin (int *a, int *b, int *c) {
free (c);
free (b);
free (a);
}
int main (void) {
int *a, *b, *c, x, flag = mk (&a, &b, &c);
while ((x = getchar ()) != -1) {
if (flag) switch (x) {
case 0:
break;
default:
goto retn;
} else if (x) goto retn;
}
retn:
if (flag) fin (a, b, c);
return 0;
}
Attached are required output files:
* gcc_bug.txt: `gcc -v -save-temps -Wall -O2 -c gcc_bug.c -o gcc_bug.o'.
* gcc_bug.ii: `sed '/^#/d; /^[ \t]*$/d' < gcc_bug.i'.
--
My current OpenPGP key:
RSA4096/0x227E8CAAB7AA186C (expires: 2020.10.19)
7077 7781 B859 5166 AE07 0286 227E 8CAA B7AA 186C
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-5.3.0/configure
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl
--target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 5.3.0'
--enable-checking=release --disable-fixed-point --disable-libstdcxx-pch
--disable-multilib --disable-nls --disable-werror --disable-symvers
--enable-__cxa_atexit --enable-esp --enable-cloog-backend
--enable-languages=c,c++,objc,java,fortran,ada --disable-libssp
--disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads
--enable-tls --with-system-zlib
Thread model: posix
gcc version 5.3.0 (Alpine 5.3.0)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-O2' '-c' '-o' 'gcc_bug.o'
'-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-strong'
/usr/libexec/gcc/x86_64-alpine-linux-musl/5.3.0/cc1 -E -quiet -v gcc_bug.c
-fno-strict-overflow -mtune=generic -march=x86-64 -Wall -fPIE
-fstack-protector-strong -O2 -fpch-preprocess -o gcc_bug.i
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/fortify
/usr/include
/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-O2' '-c' '-o' 'gcc_bug.o'
'-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-strong'
/usr/libexec/gcc/x86_64-alpine-linux-musl/5.3.0/cc1 -fpreprocessed gcc_bug.i
-fno-strict-overflow -quiet -dumpbase gcc_bug.c -mtune=generic -march=x86-64
-auxbase-strip gcc_bug.o -O2 -Wall -version -fPIE -fstack-protector-strong -o
gcc_bug.s
GNU C11 (Alpine 5.3.0) version 5.3.0 (x86_64-alpine-linux-musl)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=63321
GNU C11 (Alpine 5.3.0) version 5.3.0 (x86_64-alpine-linux-musl)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=63321
Compiler executable checksum: e0c13e9a002c6d480b493a417dbb9bdc
gcc_bug.c: In function 'main':
gcc_bug.c:18:2: warning: 'c' may be used uninitialized in this function
[-Wmaybe-uninitialized]
free (c);
^
gcc_bug.c:24:15: note: 'c' was declared here
int *a, *b, *c, x, flag = mk (&a, &b, &c);
^
gcc_bug.c:19:2: warning: 'b' may be used uninitialized in this function
[-Wmaybe-uninitialized]
free (b);
^
gcc_bug.c:24:11: note: 'b' was declared here
int *a, *b, *c, x, flag = mk (&a, &b, &c);
^
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-O2' '-c' '-o' 'gcc_bug.o'
'-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-strong'
/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/as
-v --64 -o gcc_bug.o gcc_bug.s
GNU assembler version 2.26 (x86_64-alpine-linux-musl) using BFD version (GNU
Binutils) 2.26.20160125
COMPILER_PATH=/usr/libexec/gcc/x86_64-alpine-linux-musl/5.3.0/:/usr/libexec/gcc/x86_64-alpine-linux-musl/5.3.0/:/usr/libexec/gcc/x86_64-alpine-linux-musl/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/:/usr/lib/gcc/x86_64-alpine-linux-musl/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/:/