Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12483 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15285 invoked by uid 1010); 30 Aug 2004 20:31:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 97130 invoked from network); 30 Aug 2004 20:24:53 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by pb1.pair.com with SMTP; 30 Aug 2004 20:24:53 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i7UKOrS0019941 for ; Mon, 30 Aug 2004 16:24:53 -0400 Received: from radish.cambridge.redhat.com (radish.cambridge.redhat.com [172.16.18.90]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i7UKOg307146 for ; Mon, 30 Aug 2004 16:24:42 -0400 Received: from radish.cambridge.redhat.com (localhost.localdomain [127.0.0.1]) by radish.cambridge.redhat.com (8.12.10/8.12.7) with ESMTP id i7UKOfHP013839 for ; Mon, 30 Aug 2004 21:24:41 +0100 Received: (from jorton@localhost) by radish.cambridge.redhat.com (8.12.10/8.12.10/Submit) id i7UKOfte013838 for internals@lists.php.net; Mon, 30 Aug 2004 21:24:41 +0100 Date: Mon, 30 Aug 2004 21:24:40 +0100 To: internals@lists.php.net Message-ID: <20040830202440.GA13550@redhat.com> Mail-Followup-To: internals@lists.php.net References: <20040827122550.GC29943@redhat.com> <5.1.0.14.2.20040830115720.043545d0@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5.1.0.14.2.20040830115720.043545d0@127.0.0.1> User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] [PATCH] zend_operators DVAL_TO_LVAL fix From: jorton@redhat.com (Joe Orton) On Mon, Aug 30, 2004 at 12:32:59PM -0700, Andi Gutmans wrote: > Hi Joe, > > It seems like your patch doesn't really fix anything. How is rounding to > LONG_MAX/LONG_MIN any better? The C standard says that when converting a double to a long, if the integral part of the double is outside the range which can be represented by a long, the conversion has undefined behaviour. #define DVAL_TO_LVAL(d, l) (l) = (d) > LONG_MAX ? (unsigned long) (d) : (long) (d) where d is a double and l is a long: so this has undefined behaviour for values of d greater than ULONG_MAX or smaller than LONG_MIN. #define DVAL_TO_LVAL(d, l) do { \ if ((d) > LONG_MAX) { \ l = LONG_MAX; \ } else if ((d) < LONG_MIN) { \ l = LONG_MIN; \ } else { \ l = (d); \ } \ } while (0) has well-defined behaviour for all values of 'd', since it will never attempt to assign a value to 'l' which cannot be represented by a long. > Maybe you can explain in more detail what this gcc bug you are hitting is? It seems to be an IA64-specific optimisation bug, it's really incidental to the fact that the current code is dubious. GCC evaluates the expression as either 0 or LONG_MIN if d is negative, depending on -O level. (Which is fairly nasty) joe