Using a left shift of an unsigned int by 15 and converting the result to double
does not work on sparc and creates broken code on solaris. 

To reproduce, enter the following code and compile with -O2 and run:
/* snip */
#include <stdio.h>
#include <stdlib.h>


unsigned char SampleDepthOf() { return ( 16 ); };
#define POW2(x) ((unsigned long)1 << (x))
typedef double DOUBLE;

DOUBLE pow2test()
{
    return ( DOUBLE(POW2(SampleDepthOf() - 1)) );
}

int main(int /*argc*/, char** /*argv*/)
{
    double x = pow2test();

    printf("%f\n", x);
    return ( 0 );
}
/* snip */
This code returns 0.0, not 32768.0 as it should.

The code compiles and works correctly with the optimizer disabled and
then returns the proper result.


-- 
           Summary: left-shift by 16 + int to double conversion broken in
                    optimized code
           Product: gcc
           Version: 3.4.6
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: thor at math dot tu-berlin dot de
 GCC build triplet: sparc-sun-solaris5.7
  GCC host triplet: sparc-sun-solaris5.7
GCC target triplet: sparc-sun-solaris5.7


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30290

Reply via email to