Re: Reliance on undefined behaviour in << operator

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Craig Ringer <craig(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reliance on undefined behaviour in << operator
Date: 2015-09-16 20:03:50
Message-ID: 20150916200350.GH2086@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2015-09-16 15:57:04 -0400, Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
> >> Our implementation of << is a direct wrapper around the C operator. It
> >> does not check the right-hand side's value.
> >> ... On x64 intel gcc linux it does a rotation but that's
> >> not AFAIK guaranteed by anything, and we should probably not be
> >> relying on this or exposing it at the user level.
>
> > I agree.
>
> As far as I'm concerned, what those operators mean is "whatever your
> compiler makes them mean".

According to C that's undefined behaviour. So in the extreme sense that
could mean that the instruction could trigger a SIGBUS or something.

> This is hardly the only place where we expose
> platform-dependent behavior --- see also locale dependencies, timezones,
> floating point, yadda yadda --- and I do not find it the most compelling
> place to start reversing that general approach.

But in other places We do overflow checks, so I don't think that'd be
reversal of a general approach.

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-09-16 20:08:10 Re: Additional LWLOCK_STATS statistics
Previous Message Robert Haas 2015-09-16 20:03:14 Re: Reliance on undefined behaviour in << operator