public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686"
@ 2005-09-16 11:10 larschri at pvv dot ntnu dot no
  2005-09-16 11:12 ` [Bug c/23913] " larschri at pvv dot ntnu dot no
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: larschri at pvv dot ntnu dot no @ 2005-09-16 11:10 UTC (permalink / raw)
  To: gcc-bugs

Full example files are here:
http://www.pvv.ntnu.no/~larschri/cast-bug/

The compiled program fails to do binary conversion between float and int. Both
sizeof(int) and sizeof(float) is 4, so the two floats below should have the same
binary representation after being written/read to/from the integer object.

float f1 = 4.5;
int i =    *((int*)&f1);
float f2 = *((float*)&i);
assert(f1 == f2);

$ gcc --version
gcc (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -O2 -march=i686 cast-bug.c
$ ./a.out
a.out: cast-bug.c:8: main: Assertion `f1 == f2' failed.
Aborted

-- 
           Summary: float/int binary conversion -- "-O2 -march=i686"
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: larschri at pvv dot ntnu dot no
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
@ 2005-09-16 11:12 ` larschri at pvv dot ntnu dot no
  2005-09-16 11:16 ` ebotcazou at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: larschri at pvv dot ntnu dot no @ 2005-09-16 11:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From larschri at pvv dot ntnu dot no  2005-09-16 11:12 -------
Created an attachment (id=9739)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9739&action=view)
.i file that triggers the bug.


-- 


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
  2005-09-16 11:12 ` [Bug c/23913] " larschri at pvv dot ntnu dot no
@ 2005-09-16 11:16 ` ebotcazou at gcc dot gnu dot org
  2005-09-16 11:34 ` larschri at pvv dot ntnu dot no
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-09-16 11:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2005-09-16 11:16 -------
Your code violates ISO C aliasing rules.  See the docs about -fstrict-aliasing.

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


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
  2005-09-16 11:12 ` [Bug c/23913] " larschri at pvv dot ntnu dot no
  2005-09-16 11:16 ` ebotcazou at gcc dot gnu dot org
@ 2005-09-16 11:34 ` larschri at pvv dot ntnu dot no
  2005-09-16 12:12 ` larschri at pvv dot ntnu dot no
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: larschri at pvv dot ntnu dot no @ 2005-09-16 11:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From larschri at pvv dot ntnu dot no  2005-09-16 11:34 -------
I see - thanks!

I didn't use the -Wall options when changing from C++ to C. g++ had the same
problem, but didn't give any warnings with -Wall.

-- 


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
                   ` (2 preceding siblings ...)
  2005-09-16 11:34 ` larschri at pvv dot ntnu dot no
@ 2005-09-16 12:12 ` larschri at pvv dot ntnu dot no
  2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
  2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: larschri at pvv dot ntnu dot no @ 2005-09-16 12:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From larschri at pvv dot ntnu dot no  2005-09-16 12:12 -------
I have filed this enhancment ticket: [Bug c++/23915]

-- 


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
                   ` (3 preceding siblings ...)
  2005-09-16 12:12 ` larschri at pvv dot ntnu dot no
@ 2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
  2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-16 14:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-16 14:18 -------
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***

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


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


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

* [Bug c/23913] float/int binary conversion -- "-O2 -march=i686"
  2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
                   ` (4 preceding siblings ...)
  2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
@ 2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-16 14:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-16 14:18 -------
Reopening to ...

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


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


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

end of thread, other threads:[~2005-09-16 14:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-16 11:10 [Bug c/23913] New: float/int binary conversion -- "-O2 -march=i686" larschri at pvv dot ntnu dot no
2005-09-16 11:12 ` [Bug c/23913] " larschri at pvv dot ntnu dot no
2005-09-16 11:16 ` ebotcazou at gcc dot gnu dot org
2005-09-16 11:34 ` larschri at pvv dot ntnu dot no
2005-09-16 12:12 ` larschri at pvv dot ntnu dot no
2005-09-16 14:18 ` pinskia at gcc dot gnu dot org
2005-09-16 14:18 ` pinskia at gcc dot gnu 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).