Re: gcc -Wclobbered in PostgresMain

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sergey Shinderuk <s(dot)shinderuk(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gcc -Wclobbered in PostgresMain
Date: 2023-07-08 15:11:22
Message-ID: 1632266.1688829082@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Sergey Shinderuk <s(dot)shinderuk(at)postgrespro(dot)ru> writes:
> While analyzing -Wclobbered warnings from gcc we found a true one in
> PostgresMain():
> ...
> These variables must be declared volatile, because they are read after
> longjmp(). send_ready_for_query declared there is volatile.

Yeah, you're on to something there.

> Without volatile, these variables are kept in registers and restored by
> longjump(). I think, this is harmless because the error handling code
> calls disable_all_timeouts() anyway.

Hmm. So what could happen (if these *aren't* in registers) is that we
might later uselessly call disable_timeout to get rid of timeouts that
are long gone anyway. While that's not terribly expensive, it's not
great either. What we ought to be doing is resetting these two flags
after the disable_all_timeouts call.

Having done that, it wouldn't really be necessary to mark these
as volatile. I kept that marking anyway for consistency with
send_ready_for_query, but perhaps we shouldn't?

> I also moved firstchar's declaration inside the loop where it's used, to
> make it clear that this variable needn't be volatile and is not
> preserved after longjmp().

Good idea, but then why not the same for input_message? It's fully
reinitialized each time through the loop, too.

In short, something like the attached, except I'm not totally sold
on changing the volatility of the timeout flags.

regards, tom lane

Attachment Content-Type Size
v2-fix-PostgresMain-local-vars.patch text/x-diff 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2023-07-08 15:52:11 Re: pg_basebackup check vs Windows file path limits
Previous Message Andrew Dunstan 2023-07-08 13:15:21 Re: pg_basebackup check vs Windows file path limits