public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34463]  New: Incorrect code generation from a source with double casts.
@ 2007-12-14 17:12 alexcher at quadnet dot net
  2007-12-14 17:33 ` [Bug c/34463] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: alexcher at quadnet dot net @ 2007-12-14 17:12 UTC (permalink / raw)
  To: gcc-bugs

gcc generates incorrect code from the sample program on several
recent GNU+Linux distributions running on PowerPC. The variable 'unu' is
assigned an incorrect value.

alexcher@ppc64 ~ $ uname -a
Linux ppc64 2.6.21-hardened-r3 #5 SMP Wed Jul 18 17:02:05 UTC 2007 ppc64
PPC970FX, altivec supported PowerMac7,3 GNU/Linux

alexcher@ppc64 ~ $ gcc --version
gcc (GCC) 4.1.2 (Gentoo 4.1.2)

Sample program:
#include <stdio.h>
#include <stdlib.h>

/* 
   Apparently, gcc doesn't like double casts after optimizing lnum out.

   To reproduce:
   gcc -O2 foo.c
   ./a.out

   This problem was found on gcc 4.2.1 on PowerPC with -O2 option.
*/

void foo(const char * p, float *pfnum)
{
    int lnum;
    lnum = *(int *)p;
    *pfnum = *(float *)&lnum;
}

int main()
{ 
  float one = 1.;
  float unu = 2.;
  foo( (char *)&one, &unu);
  printf("one=%f, unu=%f\n", one, unu);

  return 0;
}


-- 
           Summary: Incorrect code generation from a source with double
                    casts.
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexcher at quadnet dot net
  GCC host triplet: ppc64-Gentoo- 2.6.21-hardened-r3
GCC target triplet: ppc64-Gentoo- 2.6.21-hardened-r3


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


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

* [Bug c/34463] Incorrect code generation from a source with double casts.
  2007-12-14 17:12 [Bug c/34463] New: Incorrect code generation from a source with double casts alexcher at quadnet dot net
@ 2007-12-14 17:33 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-12-14 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-12-14 17:33 -------
Both places where you are deferencing is an aliasing violation.

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


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2007-12-14 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-14 17:12 [Bug c/34463] New: Incorrect code generation from a source with double casts alexcher at quadnet dot net
2007-12-14 17:33 ` [Bug c/34463] " 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).