-Wclobbered would be really useful if it worked --- but sadly,
on practically all gcc and clang versions, those warnings have
nearly nothing to do with reality. We typically ignore them.
Yes, in the vast majority of cases. But I believe this is not one of them. Actually, we do
not adhere to the C language standard for a setjump/logjump. Notice how the
non-volatile local variable "bool dorethrow##" utilized in the setjump/logjump block.
This topic reminds me of [0].
In fact, we do not receive a warning for a C-lang build because the compiler does not
appear to be "smart" enough to put this variable in a register. I ran a synthetic test
equivalent to PG_TRY using
godbolt.org, and the final code was the same whether
the volatile qualifier was used or not. This is not the case with the C++ build. If the
volatile qualifier is not used, the compiler optimizes this line and puts it in a register,
and we get a warning. And to get rid of this warning, you need to either turn it off via
the pragma directive, write your own version of PG_TRY with a volatile type qualifier,
or patch Postgres. None of these solutions sound good to me. You may be wondering
who will write Postgres extensions in C++. Having two different runtimes is absolute
misery, and I completely agree. However, such extensions already exist; for example,
pg_duckdb. AFAICS, it is quite popular in our area.
So, to be safe, we should follow the standard and include a volatile qualifier here. It
really costs us nothing; the resulting code will be identical for C, and we'll avoid any
future issues. In the case of C++, it will also resolve the warning.
Don't consider me as something of a formalist or someone who wants to make
mountains out of molehills. I just want to make things better. PFA trivial patch.
-- Best regards,
Maxim Orlov.