| Summary: | g++ optimiser produces bad code on right shift of 64 bit integer | ||
|---|---|---|---|
| Product: | Base System | Reporter: | earl_chew <earl_chew> |
| Component: | gnu | Assignee: | Alexander Kabaev <kan> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.0-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
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. Responsible Changed From-To: obrien->freebsd-bugs State Changed From-To: open->patched This is fixed in -current with the import of gcc-3.1. Responsible Changed From-To: freebsd-bugs->kan Assign to gcc maintainer 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. |
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; }