The following prints -1; this is undefined behavior per C99 spec §6.3.1.4, but it's 
odd nonetheless, and 
inconsistent with two similar cases, below:

        volatile const register float arg2_float_195 = FLT_MAX/666.0;
        printf(  " \t %s %lld \n " , "" ,     ( long long )    arg2_float_195  );

(The blank string and parentheses are testing artifacts.)

As an unsigned long, we get 18446744073709551615:
printf(  " \t %s %llu \n " , "" ,     ( unsigned long long )    arg2_float_195  );

As a literal constant, we get 9223372036854775807:
printf(  " \t %s ( long long )    5.1093e+35 :\t %lld \n " , "" ,     ( long long )    
5.1093e+35  );


--------
Here's the session; preprocessed file to follow.  Originally found with C99 option on, 
but also occurs 
without it.  Also occurred with DevTools 3.3.

/usr/local/gcc34/bin/gcc -v -save-temps 
../c/noerror/bugfiles/gcc_bugfiles/Float_to_long_long.c
Reading specs from /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/specs
Configured with: configure --prefix=/usr/local/gcc34
Thread model: posix
gcc version 3.4.0
 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -E -quiet -v 
-D__DYNAMIC__ ../
c/noerror/bugfiles/gcc_bugfiles/Float_to_long_long.c -fPIC -o Float_to_long_long.i
ignoring nonexistent directory 
"/usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/../../../../
powerpc-apple-darwin7.3.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/gcc34/include
 /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/include
 /usr/include
End of search list.
 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -fpreprocessed 
Float_to_long_long.i -fPIC -quiet -dumpbase Float_to_long_long.c -auxbase 
Float_to_long_long 
-version -o Float_to_long_long.s
GNU C version 3.4.0 (powerpc-apple-darwin7.3.0)
        compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 as -arch ppc -o Float_to_long_long.o Float_to_long_long.s
 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/collect2 -arch ppc 
-dynamic -o 
a.out -lcrt1.o -lcrt2.o -L/usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0 
-L/usr/local/
gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/../../.. Float_to_long_long.o -lgcc 
-lgcc_eh -lSystem |
 c++filt
[gharlane:compilerChain/tests/scripts] flash% a.out
 )    5.1093e+35 (    ( long long )    arg2_float_195 ) : 
          -1 
  )    5.1093e+35 (    ( unsigned long long )    arg2_float_195 ) : 
          18446744073709551615 
          ( long long )    5.1093e+35 :  9223372036854775807

-- 
           Summary: 5.1093e+35 (as a variable) cast to long long => -1
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: flash at pobox dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-apple-darwin7.3.0
  GCC host triplet: powerpc-apple-darwin7.3.0
GCC target triplet: powerpc-apple-darwin7.3.0


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

Reply via email to