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;
}


-- 
           Summary: optimization results in wrong argument passing
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: puvar at rambler-co dot ru


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

Reply via email to