From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-committers@postgresql.org
Subject: Re: pgsql: Use new overflow aware integer operations.
Date: Wed, 14 Feb 2018 14:30:26 -0800
Message-ID: <20180214223026.m2alym4qrdnimqrd@alap3.anarazel.de> (raw)
In-Reply-To: <20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de>
References: <E1eOvQF-00075s-D1@gemulon.postgresql.org>
<18169.1513958454@sss.pgh.pa.us>
<20171222175225.3vaod42gv34l32wv@alap3.anarazel.de>
<4294.1513968774@sss.pgh.pa.us>
<D060B40F-5781-4981-B853-509D06E7DCD0@anarazel.de>
<19898.1514415566@sss.pgh.pa.us>
<20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de>
On 2017-12-29 12:21:54 -0800, Andres Freund wrote:
> On 2017-12-27 17:59:26 -0500, Tom Lane wrote:
> > #if defined(HAVE__BUILTIN_OP_OVERFLOW)
> > return __builtin_add_overflow(a, b, result);
> > #else
> > int32 res = (int32) a + (int32) b;
> >
> > if (res > PG_INT16_MAX || res < PG_INT16_MIN)
> > + {
> > + *result = 0; /* just to keep compiler quiet */
> > return true;
> > + }
> > *result = (int16) res;
> > return false;
> > #endif
> >
> > I do not think this would cause any performance loss in our expected
> > usage, because reasonably bright compilers would detect that the store
> > is dead code and remove it. But less-bright compilers would not be
> > issuing warnings.
>
> Yea, that works for me. I wonder if we should choose an absurd sentinel
> value to prevent code from relying on one? 0x0000beef or such. Unless
> somebody protests soon-ish I'll make it so.
Pushed that way (with 0x5EED as the value, seems more appropriate ;)).
I can't convince any of my compilers to actual emit warnings in this
case, so we'll have to see whether prairiedog like this...
Greetings,
Andres Freund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: andres@anarazel.de, tgl@sss.pgh.pa.us
Subject: Re: pgsql: Use new overflow aware integer operations.
In-Reply-To: <20180214223026.m2alym4qrdnimqrd@alap3.anarazel.de>
References: <E1eOvQF-00075s-D1@gemulon.postgresql.org> <18169.1513958454@sss.pgh.pa.us> <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de> <4294.1513968774@sss.pgh.pa.us> <D060B40F-5781-4981-B853-509D06E7DCD0@anarazel.de> <19898.1514415566@sss.pgh.pa.us> <20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de> <20180214223026.m2alym4qrdnimqrd@alap3.anarazel.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox