gpdb: fileam.c:927:10: error: ‘error_caught’ is used uninitialized in this function [-Werror=uninitialized]

Greenplum version or build

$ git branch
* master

OS version and uname -a

$ cat /etc/issue.net
Ubuntu Eoan Ermine (development branch)

$ uname -a
Linux nyu-vm-ubuntu 5.2.0-8-generic #9-Ubuntu SMP Mon Jul 8 13:07:27 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ gcc-9 -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc-9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.1.0-9ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
gcc version 9.1.0 (Ubuntu 9.1.0-9ubuntu2)

autoconf options used ( config.status --config )

$ ./config.status --config
'--cache-file=/home/u/.cache/my/gpdb.debug._g__O3__march_native.cache' '--with-python' '--with-perl' '--disable-mapreduce' '--disable-orca' '--with-libxml' '--with-openssl' '--disable-codegen' '--disable-gpcloud' '--disable-gpfdist' '--disable-debug' '--disable-cassert' '--enable-depend' '--disable-coverage' '--prefix=/home/u/opt/gpdb' '--with-includes=/home/u/opt/orca/include' '--with-libraries=/home/u/opt/orca/lib' 'CC=gcc-9' 'CFLAGS=-g -O3 -march=native' 'CXX=g++-9' 'CXXFLAGS=-g -O3 -march=native'

Installation information ( pg_config )

$ pg_config
BINDIR = /home/u/opt/gpdb/bin
DOCDIR = /home/u/opt/gpdb/share/doc/postgresql
HTMLDIR = /home/u/opt/gpdb/share/doc/postgresql
INCLUDEDIR = /home/u/opt/gpdb/include
PKGINCLUDEDIR = /home/u/opt/gpdb/include/postgresql
INCLUDEDIR-SERVER = /home/u/opt/gpdb/include/postgresql/server
LIBDIR = /home/u/opt/gpdb/lib
PKGLIBDIR = /home/u/opt/gpdb/lib/postgresql
LOCALEDIR = /home/u/opt/gpdb/share/locale
MANDIR = /home/u/opt/gpdb/share/man
SHAREDIR = /home/u/opt/gpdb/share/postgresql
SYSCONFDIR = /home/u/opt/gpdb/etc/postgresql
PGXS = /home/u/opt/gpdb/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--cache-file=/home/u/.cache/my/gpdb.debug._O0__g__fuse_ld_gold__march_native.cache' '--with-python' '--with-perl' '--disable-mapreduce' '--disable-orca' '--with-libxml' '--with-openssl' '--disable-codegen' '--disable-gpcloud' '--disable-gpfdist' '--enable-debug' '--enable-cassert' '--enable-depend' '--disable-coverage' '--prefix=/home/u/opt/gpdb' '--with-includes=/home/u/opt/orca/include' '--with-libraries=/home/u/opt/orca/lib' 'CC=gcc-9' 'CFLAGS=-O0 -g -fuse-ld=gold -march=native' 'CXX=g++-9' 'CXXFLAGS=-O0 -g -fuse-ld=gold -march=native'
CC = gcc-9
CPPFLAGS = -D_GNU_SOURCE -I/usr/include/libxml2 -I/home/u/opt/orca/include -I/home/u/opt/gpdb/include
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -fno-aggressive-loop-optimizations -Wno-unused-but-set-variable -Wno-address -Wno-format-truncation -Wno-stringop-truncation -g -ggdb -O0 -g -fuse-ld=gold -march=native -std=gnu99 -Werror=uninitialized -Werror=implicit-function-declaration -I/home/u/opt/gpdb/include
CFLAGS_SL = -fPIC
LDFLAGS = -L/home/u/opt/orca/lib -Wl,--as-needed -Wl,-rpath,'/home/u/opt/gpdb/lib',--enable-new-dtags -L/home/u/opt/gpdb/lib
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lxml2 -lrt -lzstd -lrt -lcrypt -ldl -lm -L/home/u/opt/gpdb/lib
VERSION = PostgreSQL 9.4.20

Expected behavior

Should compiles successfully.

Actual behavior

Compilation failed with below error:

make -C external all
make[4]: Entering directory '/home/u/src/gpdb.git/src/backend/access/external'
gcc-9 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -fno-aggressive-loop-optimizations -Wno-unused-but-set-variable -Wno-address -Wno-format-truncation -Wno-stringop-truncation -g -O3 -march=native -std=gnu99   -Werror=uninitialized -Werror=implicit-function-declaration -I../../../../src/include -D_GNU_SOURCE -I/usr/include/libxml2  -I/home/u/opt/orca/include  -c -o fileam.o fileam.c -MMD -MP -MF .deps/fileam.Po
fileam.c: In function ‘externalgettup_custom’:
fileam.c:927:10: error: ‘error_caught’ is used uninitialized in this function [-Werror=uninitialized]
  927 |    bool  error_caught = false;
      |          ^~~~~~~~~~~~
In file included from ../../../../src/include/postgres.h:53,
                 from fileam.c:34:
../../../../src/include/utils/elog.h:425:15: error: ‘save_exception_stack’ is used uninitialized in this function [-Werror=uninitialized]
  425 |   sigjmp_buf *save_exception_stack = PG_exception_stack; \
      |               ^~~~~~~~~~~~~~~~~~~~
../../../../src/include/utils/elog.h:425:15: note: ‘save_exception_stack’ was declared here
  425 |   sigjmp_buf *save_exception_stack = PG_exception_stack; \
      |               ^~~~~~~~~~~~~~~~~~~~
fileam.c:932:4: note: in expansion of macro ‘PG_TRY’
  932 |    PG_TRY();
      |    ^~~~~~
../../../../src/include/utils/elog.h:426:25: error: ‘save_context_stack’ is used uninitialized in this function [-Werror=uninitialized]
  426 |   ErrorContextCallback *save_context_stack = error_context_stack; \
      |                         ^~~~~~~~~~~~~~~~~~
../../../../src/include/utils/elog.h:426:25: note: ‘save_context_stack’ was declared here
  426 |   ErrorContextCallback *save_context_stack = error_context_stack; \
      |                         ^~~~~~~~~~~~~~~~~~
fileam.c:932:4: note: in expansion of macro ‘PG_TRY’
  932 |    PG_TRY();
      |    ^~~~~~
cc1: some warnings being treated as errors
make[4]: *** [../../../../src/Makefile.global:826: fileam.o] Error 1
make[4]: Leaving directory '/home/u/src/gpdb.git/src/backend/access/external'

Step to reproduce the behavior

I have tested with several gcc versions, the issue is reported on gcc 7, 8 and 9; gcc-6 will not report any issue.

And gcc-9 only reports the issue with -O2, -O3 and -Ofast; there is no such issue with -O, -O0, -O1, -Os and -Og.

The reported error itself is weird:

fileam.c:927:10: error: ‘error_caught’ is used uninitialized in this function [-Werror=uninitialized]
  927 |    bool  error_caught = false;
      |          ^~~~~~~~~~~~

It reports an uninitialized variable on its initialization statement. This might be a bug of GCC, maybe it does not detect the initialization correctly, or maybe there do is an uninitialized variable but it reports on the wrong one.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I had a rough check on gpdb source code and found nothing wrong around the variables reported by gcc. So maybe we really triggered a gcc bug. In such a case we could consider adding -fno-tree-pre for this .c source file.