Hi, hackers!

While building pg_duckdb extension with PostgreSQL 17.5 we found -Wclobbered warning from gcc with PG_TRY():

g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -g -ggdb -Og -g3 -fno-omit-frame-pointer -DDEBUG -fvisibility=default -std=c++17 -Wno-sign-compare -Wshadow -Wswitch -Wunused-parameter -Wunreachable-code -Wno-unknown-pragmas -Wall -Wextra -Wno-register -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Iinclude -isystem third_party/duckdb/src/include -isystem third_party/duckdb/third_party/re2 -isystem /home/user/data/pgddb/bins/include/postgresql/server -Wno-sign-compare -Wshadow -Wswitch -Wunused-parameter -Wunreachable-code -Wno-unknown-pragmas -Wall -Wextra -I. -I./ -I/home/user/data/pgddb/bins/include/postgresql/server -I/home/user/data/pgddb/bins/include/postgresql/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o src/catalog/pgduckdb_storage.o src/catalog/pgduckdb_storage.cpp -MMD -MP -MF .deps/pgduckdb_storage.Po In file included from /home/user/data/pgddb/bins/include/postgresql/server/postgres.h:46,
                 from include/pgduckdb/utility/cpp_wrapper.hpp:6,
                 from src/pgduckdb_background_worker.cpp:19:
src/pgduckdb_background_worker.cpp: In function ‘Datum force_motherduck_sync(FunctionCallInfo)’: src/pgduckdb_background_worker.cpp:289:9: warning: variable ‘_do_rethrow’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]
  289 |         PG_TRY();
      |         ^~~~~~


Looking into a thread
https://www.postgresql.org/message-id/2eda015b-7dff-47fd-d5e2-f1a9899b90a6%40postgrespro.ru
we changed
bool _do_rethrow##__VA_ARGS__ = false; \
to
volatile bool _do_rethrow##__VA_ARGS__ = false; \
and the warning disappeared.

But what is not clear here - why does this warning happens?
According to sigsetjmp manual:
"
The compiler may optimize variables into registers, and longjmp() may restore the values of other registers in addition to the stack pointer and program counter. Consequently, the values of automatic variables are unspecified after a call to longjmp() if they meet
all the following criteria:
• they are local to the function that made the corresponding setjmp() call; • their values are changed between the calls to setjmp() and longjmp(); and
•  they are not declared as volatile.
"
In our case the first and the third statements hold. But it is not obvious here - why, where and how the local variable _do_rethrow can be changed?
And what the -Wclobbered warning really means here?
Does it makes sense to add volatile attribute to the _do_rethrow or should we just ignore that -Wclobbered warning?

Any thoughts and advices are very welcome.

Versions:

PostgreSQL: branch REL_17_STABLE
commit a3c6d92f3cb3e49bde59e52268e2d74db05d7789
Author: Michael Paquier <mich...@paquier.xyz>
Date:   Wed May 28 09:43:45 2025 +0900

pg_duckdb:
commit aaedec1cf7d7fed1018ff3767d0bd4f85ea4f89a
Author: Jelte Fennema-Nio <je...@motherduck.com>
Date:   Wed May 28 14:54:02 2025 +0200

gcc:
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

PostgreSQL config:
../configure --enable-debug --enable-cassert --enable-depend --enable-tap-tests --enable-nls --with-perl --with-icu --with-libxml --with-libxslt --with-gssapi --with-openssl --with-zstd --with-lz4 --with-ldap --with-python --prefix=$PGINSTDIR --with-pgport=$PGPORT


Kind regards,
MIkhail Litsarev


Reply via email to