Bug 27426

Summary: optimization results in wrong argument passing
Product: gcc Reporter: Pavel Uvarov <puvar>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: critical CC: adruab, Andreas.Glowatz, andreg, bobm75, boris, c.pop, cdfrey, charles, christophe.guillon, cxl, czang, d.bonekaemper, danfuzz, davids, davmac, devin, djk, dmeggy, duraid, evgeny, ezharkov, fabdouze, fm, gcc-bugs, gcc, ghouston, gino, gopalv82, grigory_zagorodnev, hayim, horst.lehser, hurbain, ja2morri, jason.elbaum, jfran, jochang, kalas, larschri, lindsayd, linuxadmin, lucho, l_heldt, mike, mor_gopal, noaml, pgonzalez, pierre.chatelier, pjh, puvar, rarob, renzo, rick.ju, spelis, steffen.zimmermann, steger, strasbur, sumii, thomas.anders, zengpan, zybi
Priority: P3    
Version: 3.4.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Pavel Uvarov 2006-05-04 16:00:51 UTC
Expected output on little-endian machines:
DEF05678 

Real output with optimization -O2 (where ???? -- is trash):
DEF0????

Compilation command: g++ -O2 t.c

Program text:

#include <stdio.h>

typedef unsigned char uint08_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;

int main()
{
   uint64_t val = uint64_t(0x123456789ABCDEF0);
   uint08_t h[6];
   *(uint16_t*)h = (val >> 32) & 0xffff;
   *(uint32_t*)(h + 2) = val & 0xffffffff;
   uint32_t res = *((uint32_t *)h);
   printf ("%08X\n", res);
   return 0;
}
Comment 1 Andrew Pinski 2006-05-04 16:02:50 UTC

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