From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6586 invoked by alias); 12 Jul 2002 16:26: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 6570 invoked by uid 71); 12 Jul 2002 16:26:01 -0000 Date: Fri, 12 Jul 2002 09:26:00 -0000 Message-ID: <20020712162601.6569.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Falk Hueffner Subject: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division Reply-To: Falk Hueffner X-SW-Source: 2002-07/txt/msg00380.txt.bz2 List-Id: The following reply was made to PR c/7284; it has been noted by GNATS. From: Falk Hueffner To: "Al Grant" Cc: 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: 12 Jul 2002 18:18:14 +0200 "Al Grant" writes: > > On 12/07/2002 15:12:01 nathan wrote: > > >Synopsis: incorrectly simplifies leftshift followed by signed power-of-2 > > >division > > > > > >State-Changed-From-To: open->closed > > >State-Changed-By: nathan > > >State-Changed-When: Fri Jul 12 07:12:01 2002 > > >State-Changed-Why: > > >not a bug. for signed types, if 'n << c' overflows, the > > >behaviour is undefined. > > > > There is no "overflow" in my sample code. The operation of shifting 128 24 bits to the left on a > > 32-bit machine produces the bit pattern 0x80000000. > > No bits overflow. > > > > The fact that a positive number may become negative when > > left-shifted is a property of the twos complement representation. > > The standard does not define signed left shift in terms of > > multiplication and certainly doesn't say that it is undefined when > > the apparently equivalent multiplication would be undefined. > > >Before refering to the standard, you should probably >read it. > > I read the C89 standard (and the C++ standard). > You are referring to C99. gcc was not defining __STDC_VERSION__, so > C89, not C99, is surely the relevant standard. The behaviour > happens even if I explicitly set -std=c89, or if I use g++ 3.1, and > you cannot justify either of those by reference to C99. Right, I just assumed it to be very unlikely that this was changed to be undefined in C99. I don't have the C89 standard; could you perhaps cite the passage that shows this was defined behaviour in C89? -- Falk