From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10197 invoked by alias); 28 Jan 2011 17:42:04 -0000 Received: (qmail 10189 invoked by uid 22791); 28 Jan 2011 17:42:03 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Jan 2011 17:41:58 +0000 Received: (qmail 12921 invoked from network); 28 Jan 2011 17:41:56 -0000 Received: from unknown (HELO digraph.polyomino.org.uk) (joseph@127.0.0.2) by mail.codesourcery.com with ESMTPA; 28 Jan 2011 17:41:56 -0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.72) (envelope-from ) id 1PisKZ-0006Jt-B7; Fri, 28 Jan 2011 17:41:55 +0000 Date: Fri, 28 Jan 2011 19:01:00 -0000 From: "Joseph S. Myers" To: Sebastian Pop cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Use HOST_WIDE_INTs in gcd and least_common_multiple. In-Reply-To: <1296235481-4039-1-git-send-email-sebpop@gmail.com> Message-ID: References: <1296235481-4039-1-git-send-email-sebpop@gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg02137.txt.bz2 On Fri, 28 Jan 2011, Sebastian Pop wrote: > +HOST_WIDE_INT > +pos_mul_hwi (HOST_WIDE_INT x, HOST_WIDE_INT y) > +{ > + if (x != 0) > + gcc_checking_assert ((HOST_WIDE_INT_MAX) / x > y); The case of equality should be OK as well - that is, >= not >. > +/* Return X multiplied by Y and check that the result does not > + overflow. */ > + > +HOST_WIDE_INT > +mul_hwi (HOST_WIDE_INT x, HOST_WIDE_INT y) > +{ > + if (x >= 0) > + { > + if (y >= 0) > + return pos_mul_hwi (x, y); > + > + return -pos_mul_hwi (x, -y); > + } > + > + if (y >= 0) > + return -pos_mul_hwi (-x, y); > + > + return pos_mul_hwi (-x, -y); All the negations here of x and y could overflow - an assertion that x and y are not HOST_WIDE_INT_MIN is probably the simplest fix. (Because pos_mul_hwi returns a positive value, the negation of that return value won't overflow, however.) -- Joseph S. Myers joseph@codesourcery.com