Re: Warning -Wclobbered in PG_TRY(...)
От | Maxim Orlov |
---|---|
Тема | Re: Warning -Wclobbered in PG_TRY(...) |
Дата | |
Msg-id | CACG=ezbo=38qYGrETTPfqbuAUqbJQCZLPBkXwvjbPvz2unb0OA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Warning -Wclobbered in PG_TRY(...) (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Warning -Wclobbered in PG_TRY(...)
|
Список | 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.
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
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
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.
-- [0] https://www.postgresql.org/message-id/flat/2eda015b-7dff-47fd-d5e2-f1a9899b90a6%40postgrespro.ru
Best regards,
Maxim Orlov.
Вложения
В списке pgsql-hackers по дате отправления: