This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/34463] New: Incorrect code generation from a source with double casts.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]