Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eV1lU-0005KJ-7Q for pgsql-committers@arkaria.postgresql.org; Fri, 29 Dec 2017 21:00:28 +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 1eV1lT-0000ec-MR for pgsql-committers@arkaria.postgresql.org; Fri, 29 Dec 2017 21:00:27 +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 1eV1lT-0000eS-4i for pgsql-committers@lists.postgresql.org; Fri, 29 Dec 2017 21:00:27 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eV1lQ-0004gD-13 for pgsql-committers@postgresql.org; Fri, 29 Dec 2017 21:00:25 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 8A178217D5; Fri, 29 Dec 2017 16:00:22 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 29 Dec 2017 16:00:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=IuYCipfv5gfa1e30ljg5hXxnERaoQ s7h7S/NTKHu9q8=; b=BrbtEfVBSuKliPw+cLFxqEYq+k2VBetrMjabxu3OdKp9Q iwyyUInLwaGl8mDbRnxp09G8mYHANW26gipnNUopy5O+Ay0ooA+wG7PGyX3BmQ30 f+TvzAb6ueqAJxeRK9+/ZJpWuwTnI+2JuTkS8Bets7lgCWCyytvtFGVh8qMdUa2j cYwtwsiLx0ezxNMOaoHJsj9AVO6T1ndPgzsYbFa8iNx0PsgLeAOd5XcMcoc9dN4Q e2imT+4bqsDb8hYT6Ex8CSC3tZBEB9KlrJgjiAZQIaKfh+8ADyI/zAOalUimW/oU qM8FfhxyQ0X9KbCnmhvyW+9LVThgy8r/TD0zrOcEA== X-ME-Sender: Received: from intern.anarazel.de (unknown [38.98.37.142]) by mail.messagingengine.com (Postfix) with ESMTPA id 11F447E168; Fri, 29 Dec 2017 16:00:21 -0500 (EST) Date: Fri, 29 Dec 2017 12:21:54 -0800 From: Andres Freund To: Tom Lane Cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Use new overflow aware integer operations. Message-ID: <20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de> References: <18169.1513958454@sss.pgh.pa.us> <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de> <4294.1513968774@sss.pgh.pa.us> <19898.1514415566@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19898.1514415566@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2017-12-27 17:59:26 -0500, Tom Lane wrote: > [ 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 warning / that I refuse to fix one? All I was saying is that I don't want to exactly define which value *result is set to in case of overflow. Without having resolved the discussion of semantics it just seemed pointless to start fixing... > > Sorry, I was being unnecessarily grumpy there. Lack of holidays does that to one ;) > 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. Agreed. > 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 = (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. Greetings, Andres Freund