Hello, the following source file (here called `gcc_bug.c') triggers
`-Wmaybe-uninitialized' when compiled with `-Os', `-O1' or stronger
optimisation, plus `-Wall':

------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

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/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/lib/../lib/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/lib/:/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-O2' '-c' '-o' 'gcc_bug.o' 
'-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-strong'
__extension__
typedef __builtin_va_list va_list;
typedef __builtin_va_list __isoc_va_list;
typedef unsigned long size_t;
typedef long ssize_t;
typedef long off_t;
typedef struct _IO_FILE FILE;
typedef union _G_fpos64_t {
 char __opaque[16];
 double __align;
} fpos_t;
extern FILE *const stdin;
extern FILE *const stdout;
extern FILE *const stderr;
FILE *fopen(const char *restrict, const char *restrict);
FILE *freopen(const char *restrict, const char *restrict, FILE *restrict);
int fclose(FILE *);
int remove(const char *);
int rename(const char *, const char *);
int feof(FILE *);
int ferror(FILE *);
int fflush(FILE *);
void clearerr(FILE *);
int fseek(FILE *, long, int);
long ftell(FILE *);
void rewind(FILE *);
int fgetpos(FILE *restrict, fpos_t *restrict);
int fsetpos(FILE *, const fpos_t *);
size_t fread(void *restrict, size_t, size_t, FILE *restrict);
size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
int fgetc(FILE *);
int getc(FILE *);
int getchar(void);
int ungetc(int, FILE *);
int fputc(int, FILE *);
int putc(int, FILE *);
int putchar(int);
char *fgets(char *restrict, int, FILE *restrict);
int fputs(const char *restrict, FILE *restrict);
int puts(const char *);
int printf(const char *restrict, ...);
int fprintf(FILE *restrict, const char *restrict, ...);
int sprintf(char *restrict, const char *restrict, ...);
int snprintf(char *restrict, size_t, const char *restrict, ...);
int vprintf(const char *restrict, __isoc_va_list);
int vfprintf(FILE *restrict, const char *restrict, __isoc_va_list);
int vsprintf(char *restrict, const char *restrict, __isoc_va_list);
int vsnprintf(char *restrict, size_t, const char *restrict, __isoc_va_list);
int scanf(const char *restrict, ...);
int fscanf(FILE *restrict, const char *restrict, ...);
int sscanf(const char *restrict, const char *restrict, ...);
int vscanf(const char *restrict, __isoc_va_list);
int vfscanf(FILE *restrict, const char *restrict, __isoc_va_list);
int vsscanf(const char *restrict, const char *restrict, __isoc_va_list);
void perror(const char *);
int setvbuf(FILE *restrict, char *restrict, int, size_t);
void setbuf(FILE *restrict, char *restrict);
char *tmpnam(char *);
FILE *tmpfile(void);
FILE *fmemopen(void *restrict, size_t, const char *restrict);
FILE *open_memstream(char **, size_t *);
FILE *fdopen(int, const char *);
FILE *popen(const char *, const char *);
int pclose(FILE *);
int fileno(FILE *);
int fseeko(FILE *, off_t, int);
off_t ftello(FILE *);
int dprintf(int, const char *restrict, ...);
int vdprintf(int, const char *restrict, __isoc_va_list);
void flockfile(FILE *);
int ftrylockfile(FILE *);
void funlockfile(FILE *);
int getc_unlocked(FILE *);
int getchar_unlocked(void);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
ssize_t getdelim(char **restrict, size_t *restrict, int, FILE *restrict);
ssize_t getline(char **restrict, size_t *restrict, FILE *restrict);
int renameat(int, const char *, int, const char *);
char *ctermid(char *);
char *tempnam(const char *, const char *);
char *cuserid(char *);
void setlinebuf(FILE *);
void setbuffer(FILE *, char *, size_t);
int fgetc_unlocked(FILE *);
int fputc_unlocked(int, FILE *);
int fflush_unlocked(FILE *);
size_t fread_unlocked(void *, size_t, size_t, FILE *);
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
void clearerr_unlocked(FILE *);
int feof_unlocked(FILE *);
int ferror_unlocked(FILE *);
int fileno_unlocked(FILE *);
int getw(FILE *);
int putw(int, FILE *);
char *fgetln(FILE *, size_t *);
int asprintf(char **, const char *, ...);
int vasprintf(char **, const char *, __isoc_va_list);
__typeof__(fgets) __orig_fgets __asm__("" "fgets"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) char 
*fgets(char *__s, int __n, FILE *__f)
{
 size_t __b = __builtin_object_size(__s, 0);
 if ((size_t)__n > __b)
  __builtin_trap();
 return __orig_fgets(__s, __n, __f);
}
__typeof__(fread) __orig_fread __asm__("" "fread"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) size_t 
fread(void *__d, size_t __n, size_t __m, FILE *__f)
{
 size_t __b = __builtin_object_size(__d, 0);
 if (__n != 0 && (__n * __m) / __n != __m)
  __builtin_trap();
 if (__n * __m > __b)
  __builtin_trap();
 return __orig_fread(__d, __n, __m, __f);
}
__typeof__(fwrite) __orig_fwrite __asm__("" "fwrite"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) size_t 
fwrite(const void *__d, size_t __n, size_t __m, FILE *__f)
{
 size_t __b = __builtin_object_size(__d, 0);
 if (__n != 0 && (__n * __m) / __n != __m)
  __builtin_trap();
 if (__n * __m > __b)
  __builtin_trap();
 return __orig_fwrite(__d, __n, __m, __f);
}
__typeof__(vsnprintf) __orig_vsnprintf __asm__("" "vsnprintf"); extern 
__inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) int 
vsnprintf(char *__s, size_t __n, const char *__f,
                                     __builtin_va_list __v)
{
 size_t __b = __builtin_object_size(__s, 0);
 if (__n > __b)
  __builtin_trap();
 return __orig_vsnprintf(__s, __n, __f, __v);
}
__typeof__(vsprintf) __orig_vsprintf __asm__("" "vsprintf"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) int 
vsprintf(char *__s, const char *__f, __builtin_va_list __v)
{
 size_t __b = __builtin_object_size(__s, 0);
 int __r;
 if (__b != (size_t)-1) {
  __r = __orig_vsnprintf(__s, __b, __f, __v);
  if (__r != -1 && (size_t)__r >= __b)
   __builtin_trap();
 } else {
  __r = __orig_vsprintf(__s, __f, __v);
 }
 return __r;
}
__typeof__(snprintf) __orig_snprintf __asm__("" "snprintf"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) int 
snprintf(char *__s, size_t __n, const char *__f, ...)
{
 size_t __b = __builtin_object_size(__s, 0);
 if (__n > __b)
  __builtin_trap();
 return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack());
}
__typeof__(sprintf) __orig_sprintf __asm__("" "sprintf"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) int 
sprintf(char *__s, const char *__f, ...)
{
 size_t __b = __builtin_object_size(__s, 0);
 int __r;
 if (__b != (size_t)-1) {
  __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack());
  if (__r != -1 && (size_t)__r >= __b)
   __builtin_trap();
 } else {
  __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack());
 }
 return __r;
}
__extension__
typedef int wchar_t;
int atoi (const char *);
long atol (const char *);
long long atoll (const char *);
double atof (const char *);
float strtof (const char *restrict, char **restrict);
double strtod (const char *restrict, char **restrict);
long double strtold (const char *restrict, char **restrict);
long strtol (const char *restrict, char **restrict, int);
unsigned long strtoul (const char *restrict, char **restrict, int);
long long strtoll (const char *restrict, char **restrict, int);
unsigned long long strtoull (const char *restrict, char **restrict, int);
int rand (void);
void srand (unsigned);
void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
void free (void *);
void *aligned_alloc(size_t alignment, size_t size);
_Noreturn void abort (void);
int atexit (void (*) (void));
_Noreturn void exit (int);
_Noreturn void _Exit (int);
int at_quick_exit (void (*) (void));
_Noreturn void quick_exit (int);
char *getenv (const char *);
int system (const char *);
void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void 
*, const void *));
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
int abs (int);
long labs (long);
long long llabs (long long);
typedef struct { int quot, rem; } div_t;
typedef struct { long quot, rem; } ldiv_t;
typedef struct { long long quot, rem; } lldiv_t;
div_t div (int, int);
ldiv_t ldiv (long, long);
lldiv_t lldiv (long long, long long);
int mblen (const char *, size_t);
int mbtowc (wchar_t *restrict, const char *restrict, size_t);
int wctomb (char *, wchar_t);
size_t mbstowcs (wchar_t *restrict, const char *restrict, size_t);
size_t wcstombs (char *restrict, const wchar_t *restrict, size_t);
size_t __ctype_get_mb_cur_max(void);
int posix_memalign (void **, size_t, size_t);
int setenv (const char *, const char *, int);
int unsetenv (const char *);
int mkstemp (char *);
int mkostemp (char *, int);
char *mkdtemp (char *);
int getsubopt (char **, char *const *, char **);
int rand_r (unsigned *);
char *realpath (const char *restrict, char *restrict);
long int random (void);
void srandom (unsigned int);
char *initstate (unsigned int, char *, size_t);
char *setstate (char *);
int putenv (char *);
int posix_openpt (int);
int grantpt (int);
int unlockpt (int);
char *ptsname (int);
char *l64a (long);
long a64l (const char *);
void setkey (const char *);
double drand48 (void);
double erand48 (unsigned short [3]);
long int lrand48 (void);
long int nrand48 (unsigned short [3]);
long mrand48 (void);
long jrand48 (unsigned short [3]);
void srand48 (long);
unsigned short *seed48 (unsigned short [3]);
void lcong48 (unsigned short [7]);
void *alloca(size_t);
char *mktemp (char *);
int mkstemps (char *, int);
int mkostemps (char *, int, int);
void *valloc (size_t);
void *memalign(size_t, size_t);
int getloadavg(double *, int);
int clearenv(void);
__extension__
__typeof__(realpath) __orig_realpath __asm__("" "realpath"); extern __inline__ 
__attribute__((__always_inline__,__gnu_inline__,__artificial__)) char 
*realpath(const char *__p, char *__r)
{
 size_t __b = __builtin_object_size(__r, 0);
 if (__r) {
  char __buf[4096], *__ret;
  size_t __l;
  __ret = __orig_realpath(__p, __buf);
  if (!__ret)
   return ((void*)0);
  __l = __builtin_strlen(__ret) + 1;
  if (__l > __b)
   __builtin_trap();
  __builtin_memcpy(__r, __ret, __l);
  return __r;
 }
 return __orig_realpath(__p, __r);
}
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;
}

Reply via email to