Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1em5ZR-0000CF-Qw for pgsql-committers@arkaria.postgresql.org; Wed, 14 Feb 2018 22:30: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 1em5ZR-0001qv-17 for pgsql-committers@arkaria.postgresql.org; Wed, 14 Feb 2018 22:30: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 1em5ZQ-0001qk-HM for pgsql-committers@lists.postgresql.org; Wed, 14 Feb 2018 22:30:32 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1em5ZN-0005o5-7Y for pgsql-committers@postgresql.org; Wed, 14 Feb 2018 22:30:31 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DBFE220C2C; Wed, 14 Feb 2018 17:30:27 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 14 Feb 2018 17:30:27 -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=fm2; bh=7d7xi82J2Zxhzai8r6Y9I2fpTLB/g FWDAFxx0TktPfo=; b=ANPOD3WgKDARqGvT0se+TBS3i3hKA2zy3ks8mngNg5Nrx 9G1htLdBya5XmptokppMoRKBzF2shQUMHy1JTj3o3RQZ6ulJk8LdKlB3duz2Bprw LSYrCxzLORuy1Zv0cPNUMZEcNHEdEe036BBi7BeJL7Ctr5ASnR7Mlmlm6q17fb2M LdlIAC9tFjhC7TO/eEXAz9bqs0HnROnp2Tj7Uieey6Wx7xUOlhAAb8oS5Wr7OncA wg4ZaaNPTVQgd13sJu1iq1Ape2dSL0yotfATWkXhAR1tU3lsTJN3PbGCRc6VAcyO 0nxNvsepjbmocjDfmOm7e2QLfGVJKbPXCAWDObXmw== X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id 94101248AF; Wed, 14 Feb 2018 17:30:27 -0500 (EST) Date: Wed, 14 Feb 2018 14:30:26 -0800 From: Andres Freund To: Tom Lane Cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Use new overflow aware integer operations. Message-ID: <20180214223026.m2alym4qrdnimqrd@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> <20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171229202154.crqrq3s7ssqyqn5s@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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