Bug 34463 - Incorrect code generation from a source with double casts.
Summary: Incorrect code generation from a source with double casts.
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-14 17:12 UTC by Alex Cherepanov
Modified: 2007-12-14 17:33 UTC (History)
22 users (show)

See Also:
Host: ppc64-Gentoo- 2.6.21-hardened-r3
Target: ppc64-Gentoo- 2.6.21-hardened-r3
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Cherepanov 2007-12-14 17:12:32 UTC
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;
}
Comment 1 Andrew Pinski 2007-12-14 17:33:28 UTC
Both places where you are deferencing is an aliasing violation.

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