[Dropping coreutils from CC.]

Pádraig Brady wrote:
> Actually different -Wmaybe-initialized warnings can trigger at various 
> optimization levels.

That's an interesting observation. Indeed, compiling a testdir of all of gnulib
at various optimization levels with gcc 13.1.0, through commands like this:

  export CPPFLAGS=-Wall
  mkdir build-O0; cd build-O0; CFLAGS=-O0 ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..
  mkdir build-O1; cd build-O1; CFLAGS=-O1 ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..
  mkdir build-O2; cd build-O2; CFLAGS=-O2 ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..
  mkdir build-O3; cd build-O3; CFLAGS=-O3 ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..
  mkdir build-Os; cd build-Os; CFLAGS=-Os ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..
  mkdir build-Og; cd build-Og; CFLAGS=-Og ../configure 2>&1 | tee log1; make 
2>&1 | tee log2; cd ..

I get warnings at various levels:

* All optimizations levels:
../../gllib/astrxfrm.c:159:19: warning: pointer 'result' may be used after 
'realloc' [-Wuse-after-free]
../../gllib/get-rusage-data.c:354:1: warning: 'get_rusage_data_via_iterator' 
defined but not used [-Wunused-function]
../../gllib/hamt.c:201:1: warning: 'init_element' defined but not used 
[-Wunused-function]
../../gltests/../gllib/stack.h:75:24: warning: 'stack_current_base' defined but 
not used [-Wunused-function]

* -O0 only:
../../gllib/nstrftime.c:148:31: warning: 'memset' specified size 
18446744073709551615 exceeds maximum object size 9223372036854775807 
[-Wstringop-overflow=]
../../gllib/nstrftime.c:147:32: warning: 'memset' specified size 
18446744073709551615 exceeds maximum object size 9223372036854775807 
[-Wstringop-overflow=]

* -O1, -O2, -O3 only:
../../gllib/vasnprintf.c:945:26: warning: argument 1 value 
'18446744073709551615' exceeds maximum object size 9223372036854775807 
[-Walloc-size-larger-than=]

* -O1, -O2, -O3, -Os only:
../../gllib/vasnprintf.c:1392:10: warning: 'e' may be used uninitialized 
[-Wmaybe-uninitialized]
../../gllib/vasnprintf.c:1410:10: warning: 'e' may be used uninitialized 
[-Wmaybe-uninitialized]

* -O1, -O2, -O3, -Og, -Os only:
../../gllib/getndelim2.c:191:23: warning: 'c' may be used uninitialized 
[-Wmaybe-uninitialized]

* -O2, -O3, -Os only:
../../gllib/astrxfrm.c:177:1: warning: function may return address of local 
variable [-Wreturn-local-addr]

* -O2, -O3 only:
../../gllib/canonicalize.c:385:33: warning: 'end_idx' may be used uninitialized 
[-Wmaybe-uninitialized]

* -Og only:
../../gllib/bitset/list.c:458:22: warning: 'tmp' may be used uninitialized 
[-Wmaybe-uninitialized]

I've seen many of these warnings and regularly ignored them. But one of these
warnings points to a real bug (in astrxfrm.c), that was sitting there since
the beginning.

The lesson I learn from this (once again — I already knew it before...) that
it is important to have a warning-free build on glibc systems.

Bruno




Reply via email to