Skip site navigation (1) Skip section navigation (2)

Re: ANSI-strict pointer aliasing rules

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: mark(at)mark(dot)mielke(dot)cc
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>,Taral <taralx(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ANSI-strict pointer aliasing rules
Date: 2006-04-27 15:30:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Thu, Apr 27, 2006 at 11:08:59AM -0400, mark(at)mark(dot)mielke(dot)cc wrote:
> ... If
> PostgreSQL isn't alias safe - it means that there is casting
> happening, that is not generally accepted as valid, minimizing the
> optimization potential of the code, and certainly not guaranteed to be
> correct. Every cast in C has the potential to contain bugs today, or
> tomorrow when somebody changes the lvalue or rvalue. If the types are
> incompatible, according the compiler, the odds of a bug happening today
> or tomorrow become greater.

You're right, PostgreSQL uses a form of subclassing, so that a (for
example) struct ArrayRefExprState is occasionally referred to using a
(struct ExprState*) or even a (struct Node*). In C, the logical way to
get that to work it by casting, do you have a better way?

The fact is, strict-aliasing only breaks things in the name of

> I think we can agree on the intrusiveness of the change needing to
> be linear or less to the value of the change. If the fix is simple,
> and it generates a 1% - 2% gain - you are buying both performance,
> and correctness. Personally, I value correctness. I think some would
> value performance though.

The fix is not simple. We wouldn't have disabled it if the fix was
easy. Basically, with strict-aliasing enabled, things break. The
compiler won't identify all the issues for you, how do you know you're
safe? So the system is actually *more* correct with strict-aliasing
disabled, because then it does exactly what the code says...

The two major other places we use casts are converting Datums to their
actual types, and our MemSet which replaces the braindead GCC one.

Have a nice day,
Martijn van Oosterhout   <kleptog(at)svana(dot)org>
> From each according to his ability. To each according to his ability to litigate.

In response to


pgsql-hackers by date

Next:From: Tom LaneDate: 2006-04-27 15:32:06
Subject: Re: Summer of Code idea
Previous:From: Zeugswetter Andreas DCP SDDate: 2006-04-27 15:25:09
Subject: Re: ANSI-strict pointer aliasing rules

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group