Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSRUn-00058i-F5 for pgsql-committers@arkaria.postgresql.org; Fri, 22 Dec 2017 17:52:33 +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 1eSRUm-00047k-0H for pgsql-committers@arkaria.postgresql.org; Fri, 22 Dec 2017 17:52:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eSRUl-00047a-JF for pgsql-committers@lists.postgresql.org; Fri, 22 Dec 2017 17:52:31 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eSRUi-0002UE-MJ for pgsql-committers@postgresql.org; Fri, 22 Dec 2017 17:52:30 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B6F1C20C37; Fri, 22 Dec 2017 12:52:26 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Fri, 22 Dec 2017 12:52:26 -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=hyYYSbvgVPWdghwe65+rDs0HRt527 CFHGhCGmTOgMD0=; b=pbo4o6R2+lIn3AdeiQ9IJo7eWeyIM1yP3QmiATPqkqvlB n7zRKc4QhZonMNSfDHlH6VfHIxO5mps0Yf1iTCti+cd0xr3GXqY7T2qozl3R7Syd FI+DChv/jCN7JxaBxPKzWqAZIgeOvYbcYH+HJdrvPGfFcOpXllzD/KI40CwpLAZC dCu6PB0tnlhmvUrfqIV+1GOmWU/R6I6CvrO9UXaNjx2+XnRnKoF+UxEFeM4B7LHk AL55Vv4aG6NAW7r299JGs7CrwOCsUcU52oAArkuVtCdF4P8NQnMhDtu5/hYPxPTq aWzeo/MPMP18za+HlqZIdJmg1g5NfPpy059ilkoeg== X-ME-Sender: Received: from intern.anarazel.de (p5de63f33.dip0.t-ipconnect.de [93.230.63.51]) by mail.messagingengine.com (Postfix) with ESMTPA id 66DDA2465D; Fri, 22 Dec 2017 12:52:26 -0500 (EST) Date: Fri, 22 Dec 2017 09:52:25 -0800 From: Andres Freund To: Tom Lane Cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Use new overflow aware integer operations. Message-ID: <20171222175225.3vaod42gv34l32wv@alap3.anarazel.de> References: <18169.1513958454@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18169.1513958454@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2017-12-22 11:00:54 -0500, Tom Lane wrote: > Andres Freund 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