From nobody@FreeBSD.ORG  Wed Sep 20 15:50:36 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 1F12637B423; Wed, 20 Sep 2000 15:50:36 -0700 (PDT)
Message-Id: <20000920225036.1F12637B423@hub.freebsd.org>
Date: Wed, 20 Sep 2000 15:50:36 -0700 (PDT)
From: earl_chew@agilent.com
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: g++ optimiser produces bad code on right shift of 64 bit integer
X-Send-Pr-Version: www-1.0

>Number:         21433
>Category:       gnu
>Synopsis:       g++ optimiser produces bad code on right shift of 64 bit integer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 20 16:00:01 PDT 2000
>Closed-Date:    Thu Nov 13 14:49:28 PST 2003
>Last-Modified:  Thu Nov 13 14:49:28 PST 2003
>Originator:     Earl Chew
>Release:        4.0-RELEASE
>Organization:
Agilent Technologies
>Environment:
FreeBSD bna2188.canada.agilent.com 4.0-RELEASE FreeBSD 4.0-RELEASE #0: Mon Mar 2
0 22:50:22 GMT 2000     root@monster.cdrom.com:/usr/src/sys/compile/GENERIC  i38
6
>Description:
The attached test harness fragment dealing with >> on 64 bit integers
fails when optimisation is enabled.

The program works when no optimisation is used.

Compile with g++ -O foo.cc. Running the program yields:

0x8888222233334444 0
0x8888222233334444 0xffffffff33334444
Failed: Signed negative right shift identity operation

>How-To-Repeat:
#include <stdio.h>

typedef unsigned long long AtoUInt64T;
typedef long long AtoInt64T;

typedef AtoUInt64T U;
typedef AtoInt64T S;

int main()
{
    do
    {
        S  r ((AtoUInt64T) ( 0x88882222UL ) << 32 |
              (AtoUInt64T) ( 0x33334444UL )) ;
        S  a ((AtoUInt64T) ( 0x88882222UL ) << 32 |
             (AtoUInt64T) ( 0x33334444UL )) ;

        int  b = 0x0+0x00 ;
        S  c;

        c = a >> b;

        if (c != r)
        {
            printf("0x%llx %d\n", a, b);
            printf("0x%llx 0x%llx\n", r, c);
            printf("Failed: %s\n",
                "Signed negative right shift identity operation" );
            abort();
        }
    } while (0) ;

    return 0;
}

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: phk 
Responsible-Changed-When: Mon Dec 18 12:39:56 PST 2000 
Responsible-Changed-Why:  
I'm signing this over to our GCC maintainer, but I suspect you may want 
to take this up with the GCC people directly. 

The included code reproduces the problem on my machine. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21433 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Mon Sep 10 09:26:46 PDT 2001 
Responsible-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=21433 
State-Changed-From-To: open->patched 
State-Changed-By: mp 
State-Changed-When: Wed Jul 3 07:51:17 PDT 2002 
State-Changed-Why:  
This is fixed in -current with the import of gcc-3.1. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21433 
Responsible-Changed-From-To: freebsd-bugs->kan 
Responsible-Changed-By: kris 
Responsible-Changed-When: Sat Jul 12 17:21:58 PDT 2003 
Responsible-Changed-Why:  
Assign to gcc maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21433 
State-Changed-From-To: patched->closed 
State-Changed-By: kan 
State-Changed-When: Thu Nov 13 14:48:13 PST 2003 
State-Changed-Why:  
The bug is fixes in GCC 3.x series and GCC 2.95.x is closed  
for development, so this bug has no chances at being fixed 
there. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=21433 
>Unformatted:
