Bug 21433

Summary: g++ optimiser produces bad code on right shift of 64 bit integer
Product: Base System Reporter: earl_chew <earl_chew>
Component: gnuAssignee: Alexander Kabaev <kan>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-RELEASE   
Hardware: Any   
OS: Any   

Description earl_chew 2000-09-21 00:00:01 UTC
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;
}
Comment 1 Poul-Henning Kamp freebsd_committer freebsd_triage 2000-12-18 20:39:56 UTC
Responsible Changed
From-To: freebsd-bugs->obrien

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.
Comment 2 David E. O'Brien freebsd_committer freebsd_triage 2001-09-10 17:26:46 UTC
Responsible Changed
From-To: obrien->freebsd-bugs
Comment 3 Mark Peek freebsd_committer freebsd_triage 2002-07-03 15:51:17 UTC
State Changed
From-To: open->patched

This is fixed in -current with the import of gcc-3.1.
Comment 4 Kris Kennaway freebsd_committer freebsd_triage 2003-07-13 01:21:58 UTC
Responsible Changed
From-To: freebsd-bugs->kan

Assign to gcc maintainer
Comment 5 Alexander Kabaev freebsd_committer freebsd_triage 2003-11-13 22:48:13 UTC
State Changed
From-To: patched->closed

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.