From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20201 invoked by alias); 12 Jul 2002 19:56:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 20156 invoked by uid 71); 12 Jul 2002 19:56:01 -0000 Date: Fri, 12 Jul 2002 12:56:00 -0000 Message-ID: <20020712195601.20155.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Nathan Sidwell Subject: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division Reply-To: Nathan Sidwell X-SW-Source: 2002-07/txt/msg00390.txt.bz2 List-Id: The following reply was made to PR c/7284; it has been noted by GNATS. From: Nathan Sidwell To: Al Grant Cc: nathan@cs.bris.ac.uk, falk.hueffner@student.uni-tuebingen.de, nathan@gcc.gnu.org, algrant@acm.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division Date: Fri, 12 Jul 2002 20:45:50 +0100 Al Grant wrote: > > >you need to read more carefully. > >KnR 2 A7.8 says the same as C99, > > You need to read more carefully. K&R2 says something quite different from C99. It says that in the absence of overflow, the operation is equivalent to a > multiplication. It does _not_ say that if the multiplication overflows the result of the shift is undefined, let alone that program behavior is undefined. oops, how did I manage to misread that? A7 says that 'most existing C implementations ignore overflow in evaluation of signed integral expressions and assignemnts, but this behaviour is not guaranteed.' > >C++ says [5]/5 that if the result is not in the range >of representable values, > >the behaviour is undefined. > > But left-shift is an operation on the representation, i.e. the bit pattern. The *implementation* of left-shift is an operation on representation. The abstract left shift operation applies to values. > For signed left-shift (in C89 and C++) it is not defined any other way. C++ says it that the bit pattern is left shifted and vacated bit positions are zero filled. That we agree on. What we disagree is what happens to bits 'falling off the top' (be they zero or one). I contend that if the exact result (which will require 32+c bits to represent), is not representable in 32 bits, then the behaviour is undefined (as [5]/5 says). You contend that the result is reduced modulo 2^32. But then why does C++ then go on to say 'if E1 is unsigned type ...' to specify such a modulo reduction for unsigned types? > How is it meaningful to talk about the representability of operations on the representation, and say that the result of such an operation might be unrepresentable? the left shift is independant of bit length, it is the truncation of the exact result to a representable format which gives the problem. > Representability is a property of the integers as numbers. Representability is a property of representation formats. > It might be meaningful to think about the result of such an operation > having a representation that did not correspond to any value (e.g. was > a trap representation) but a non-valued representation is a totally > different concept from a non-representable value. Besides, there are > no such integer representations on the platform for which I reported > the bug. that would be valid implementation of undefined behaviour. nathan -- Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC 'But that's a lie.' - 'Yes it is. What's your point?' nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org