public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result
@ 2004-01-21 18:18 larue at cadence dot com
  2004-01-21 18:31 ` [Bug c/13793] " larue at cadence dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: larue at cadence dot com @ 2004-01-21 18:18 UTC (permalink / raw)
  To: gcc-bugs

Take this simple C program
#include <stdio.h>
int main(int argc, char** argv)
{
   double dummy = -5;
   printf("The following lines should match:\n");
   printf("double dummy = -5; (unsigned long) (dummy) = %lu \n", (unsigned 
long) dummy);
   printf("(unsigned long) (-5.0)                     = %lu \n", (unsigned 
long) (-5.0));
}

gcc -m64 gcc64bitIntegerConversionBug.c
humdinger{ larue 187}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 9223372036854775807 
(unsigned long) (-5.0)                     = 18446744073709551611 

If we don't use -m64 we get the right answers
humdinger{ larue 153}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 4294967291 
(unsigned long) (-5.0)                     = 4294967291 


Here are the results using the Solaris native compiler:
humdinger{ larue 154}: cc -xarch=v9 gcc64bitIntegerConversionBug.c
"gcc64bitIntegerConversionBug.c", line 7: warning: conversion of double to 
integral is out of range
humdinger{ larue 155}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 18446744073709551611 
(unsigned long) (-5.0)                     = 18446744073709551611 

Here are the specifics on my environment:

humdinger{ larue 139}:uname -a
SunOS humdinger 5.7 Generic_106541-23 sun4u sparc SUNW,Ultra-4
humdinger{ larue 140}:g++ -v
Reading specs from /dv/tools/3rdParty/gcc/3.2/bin/../lib/gcc-lib/sparc-sun-
solaris2.7/3.2/specs
Configured with: ../configure --prefix= --enable-shared=libgcc,libstdc++ --
enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.2

-- 
           Summary: On 64 bit, casting neg value to unsigned long gives
                    incorrect result
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: larue at cadence dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/13793] On 64 bit, casting neg value to unsigned long gives incorrect result
  2004-01-21 18:18 [Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result larue at cadence dot com
@ 2004-01-21 18:31 ` larue at cadence dot com
  2004-01-21 18:34 ` [Bug target/13793] " pinskia at gcc dot gnu dot org
  2004-01-21 21:20 ` falk at debian dot org
  2 siblings, 0 replies; 4+ messages in thread
From: larue at cadence dot com @ 2004-01-21 18:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From larue at cadence dot com  2004-01-21 18:31 -------
We should remove the IGNORE.gcc_64bit file from 
automatic/reference/datatypes/misc/test02 once this bug is fized.

-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/13793] On 64 bit, casting neg value to unsigned long gives incorrect result
  2004-01-21 18:18 [Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result larue at cadence dot com
  2004-01-21 18:31 ` [Bug c/13793] " larue at cadence dot com
@ 2004-01-21 18:34 ` pinskia at gcc dot gnu dot org
  2004-01-21 21:20 ` falk at debian dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-21 18:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-21 18:34 -------
I think this was fixed for 3.3 but I do not know, can you try a 3.3 based compiler?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target
           Keywords|                            |wrong-code


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/13793] On 64 bit, casting neg value to unsigned long gives incorrect result
  2004-01-21 18:18 [Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result larue at cadence dot com
  2004-01-21 18:31 ` [Bug c/13793] " larue at cadence dot com
  2004-01-21 18:34 ` [Bug target/13793] " pinskia at gcc dot gnu dot org
@ 2004-01-21 21:20 ` falk at debian dot org
  2 siblings, 0 replies; 4+ messages in thread
From: falk at debian dot org @ 2004-01-21 21:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From falk at debian dot org  2004-01-21 21:20 -------
6.3.1.4 says: If the value of the integral part cannot be represented by
the integer type, the behavior is undefined.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-21 21:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-21 18:18 [Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result larue at cadence dot com
2004-01-21 18:31 ` [Bug c/13793] " larue at cadence dot com
2004-01-21 18:34 ` [Bug target/13793] " pinskia at gcc dot gnu dot org
2004-01-21 21:20 ` falk at debian dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).