Re: Warning -Wclobbered in PG_TRY(...) - Mailing list pgsql-hackers

From Maxim Orlov
Subject Re: Warning -Wclobbered in PG_TRY(...)
Date
Msg-id CACG=ezbo=38qYGrETTPfqbuAUqbJQCZLPBkXwvjbPvz2unb0OA@mail.gmail.com
Whole thread Raw
In response to Re: Warning -Wclobbered in PG_TRY(...)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Warning -Wclobbered in PG_TRY(...)
List pgsql-hackers

On Thu, 29 May 2025 at 14:14, Tom Lane <tgl@sss.pgh.pa.us> wrote:
-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.
Attachment

pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: pg18: Virtual generated columns are not (yet) safe when superuser selects from them
Next
From: Tom Lane
Date:
Subject: Re: Fixing memory leaks in postgres_fdw