Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUKfe-0006la-D5 for pgsql-committers@arkaria.postgresql.org; Wed, 27 Dec 2017 22:59:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUKfd-0005As-I0 for pgsql-committers@arkaria.postgresql.org; Wed, 27 Dec 2017 22:59:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eUKfd-0005Ai-A3 for pgsql-committers@lists.postgresql.org; Wed, 27 Dec 2017 22:59:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eUKfa-0005qc-Em for pgsql-committers@postgresql.org; Wed, 27 Dec 2017 22:59:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vBRMxQWh019899; Wed, 27 Dec 2017 17:59:26 -0500 From: Tom Lane To: Andres Freund cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Use new overflow aware integer operations. In-reply-to: References: <18169.1513958454@sss.pgh.pa.us> <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de> <4294.1513968774@sss.pgh.pa.us> Comments: In-reply-to Andres Freund message dated "Sat, 23 Dec 2017 00:16:42 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19897.1514415566.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 27 Dec 2017 17:59:26 -0500 Message-ID: <19898.1514415566@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk [ back from Christmas break ] Andres Freund writes: > On December 22, 2017 7:52:54 PM GMT+01:00, Tom Lane = wrote: >> I will not accept an implementation that spews compiler warnings >> all over the place, which is what this one is doing. Please fix that, >> or else I will. > Are you seriously implying that I'm suggesting that we live with a warni= ng / that I refuse to fix one? All I was saying is that I don't want to ex= actly define which value *result is set to in case of overflow. Without ha= ving resolved the discussion of semantics it just seemed pointless to star= t fixing... Sorry, I was being unnecessarily grumpy there. I follow your point about not wanting to constrain the implementation to yield the correct low-order bits if we don't actually need that behavior ... but I'm still not happy about the warnings. What do you think of having the fallback code explicitly set the output variable to zero (or any other fixed value) on overflow, like #if defined(HAVE__BUILTIN_OP_OVERFLOW) return __builtin_add_overflow(a, b, result); #else int32 res =3D (int32) a + (int32) b; if (res > PG_INT16_MAX || res < PG_INT16_MIN) + { + *result =3D 0; /* just to keep compiler quiet */ return true; + } *result =3D (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. regards, tom lane