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: Fri, 22 Dec 2017 09:52:25 -0800
Message-ID: <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de> (raw)
In-Reply-To: <18169.1513958454@sss.pgh.pa.us>
References: <E1eOvQF-00075s-D1@gemulon.postgresql.org>
<18169.1513958454@sss.pgh.pa.us>
Hi,
On 2017-12-22 11:00:54 -0500, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > Use new overflow aware integer operations.
>
> I just tried to compile manually on prairiedog for the first time since
> this went in, and noticed that it now produces a boatload of warnings
> like
>
> int.c: In function 'int2pl':
> int.c:735: warning: 'result' may be used uninitialized in this function
>
> I think it's entirely within its rights to complain, because
> the non-builtin code paths in int.h look like
>
> int32 res = (int32) a + (int32) b;
>
> if (res > PG_INT16_MAX || res < PG_INT16_MIN)
> return true;
> *result = (int16) res;
> return false;
>
> and so if an overflow occurs then *result won't get set.
>
> I do not think it is reasonable for these functions to not set the
> output variable at all in the overflow case; it is not their job
> to opine on whether the caller may use the result.
I don't agree. Please note that that the function's documentation
explicitly says "The content of *result is implementation defined in
case of overflow.".
> Furthermore, this is an incorrect emulation of the built-in functions;
> the gcc manual clearly says
> These built-in functions promote the first two operands into
> infinite precision signed type and perform addition on those
> promoted operands. The result is then cast to the type the third
> pointer argument points to and stored there. If the stored result
> is equal to the infinite precision result, the built-in functions
> return false, otherwise they return true.
>
> So as coded, there is a difference of behavior depending on whether
> you have the built-in, and that cannot be anything but bad.
The problem is that other intrinsic implementation we might want to use
in the future, like microsoft's, do *not* exactly behave that way. So I
think defining this as implementation defined is the right thing to do.
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: <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de>
References: <E1eOvQF-00075s-D1@gemulon.postgresql.org> <18169.1513958454@sss.pgh.pa.us> <20171222175225.3vaod42gv34l32wv@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