Bug 131082

Summary: ia64 double conversion bug
Product: [Fedora] Fedora Reporter: Joe Orton <jorton>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: ia64   
OS: Linux   
Whiteboard:
Fixed In Version: 3.4.1-10 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-01 09:46:34 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joe Orton 2004-08-27 12:09:51 UTC
gcc-3.4.1-9, ia64, dist-fc3 buildroot.

bash-3.00# cat dbl.c
#include <stdio.h>
#include <limits.h>
int main(int argc, char **argv)
{
   double d = -12.345;
   long l = (d > LONG_MAX) ? (unsigned long) d : (long) d;
   printf("%ld\n", l);
   return 0;
}
bash-3.00# gcc -Wall dbl.c
bash-3.00# ./a.out
-9223372036854775808
bash-3.00# gcc -O2 -Wall dbl.c
bash-3.00# ./a.out
0

Yes the program is weird and stupid, but it seems to have well-defined
behaviour by C99, AFAICT.

if the line is changed to, e.g.:

   long l = (d > LONG_MAX) ? (unsigned long) (puts(""), d) : (long) d;

it prints -12, also.

Comment 1 Joe Orton 2004-08-27 12:11:08 UTC
Forgot to mention: the program prints -12 on all our other platforms,
as expected.