Re: longjmp clobber warnings are utterly broken in modern gcc - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: longjmp clobber warnings are utterly broken in modern gcc
Date
Msg-id 20150201145650.GA2529@svana.org
Whole thread Raw
In response to Re: longjmp clobber warnings are utterly broken in modern gcc  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: longjmp clobber warnings are utterly broken in modern gcc  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: longjmp clobber warnings are utterly broken in modern gcc  (Heikki Linnakangas <hlinnakangas@vmware.com>)
List pgsql-hackers
On Sun, Jan 25, 2015 at 07:11:12PM -0500, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > On Sun, Jan 25, 2015 at 02:02:47PM -0500, Tom Lane wrote:
> > It's a bit of a long shot, but perhaps if you put something like:
>
> > asm volatile("":"":"":"memory")
>
> > at the beginning of the catch-block it might convince the compiler to
> > forget any assumptions about what is in the local variables...
>
> Meh.  Even if that worked for gcc (which as you say is uncertain),
> it would help not at all for other compilers.  The POSIX requirements
> for portable code are clear: we need a "volatile" marker on affected
> variables.

Never mind, it doesn't work. It's not that GCC doesn't know setjmp() is
special, it does (the returns_twice attribute).  So GCC does the above
effectivly itself.  The problem is that local variables may be stored
in memory over calls in the PG_TRY() block, volatile is a sledgehammer
way of preventing that.

The problem is, GCC doesn't know anything about what the return value
of setjmp() means which means that it can never produce any sensible
warnings in this area.

If you want the compiler to catch this, I don't see any way without
requiring the code to indicate specifically which local variables it
intends to use, or not using the locals at all by using a seperate
cleanup function (as discussed elsewhere in this thread).  With
information about the locals you might be able to conjure some GCC
macros to set things up to complain if you use anything else.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.  -- Arthur Schopenhauer

pgsql-hackers by date:

Previous
From: Álvaro Hernández Tortosa
Date:
Subject: Re: Fwd: [GENERAL] 4B row limit for CLOB tables
Next
From: Tom Lane
Date:
Subject: Re: longjmp clobber warnings are utterly broken in modern gcc