https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88739
Bug ID: 88739 Summary: union bug on ARM64 Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dongjianqiang2 at huawei dot com Target Milestone: --- Created attachment 45364 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45364&action=edit demo code to recur error #include<stdio.h> typedef unsigned int U32; typedef unsigned short U16; typedef unsigned char U8; typedef struct MEM_HEAD_4DW { /* first word */ U32 b11 : 1; U32 b12 : 3; U32 b13 : 3; U32 b14 : 1; U32 b15 : 16; U32 b16 : 8; /* second word */ U32 b21 : 16; U32 b22 : 1; U32 b23 : 4; U32 b24 : 11; /* third word */ U32 b31 : 32; /* fourth word */ U32 b30AddrL : 30; U32 b2AddrType : 2; }MEM_REQ_HEAD_4DW; typedef union HEAD_DW4_UNION { MEM_REQ_HEAD_4DW strMemHead; U32 aulValue[4]; U16 ausValue[8]; U8 aucValue[16]; }HEAD_REQ_DW4_UNION; U32 Test_func(U32 ulAddr) { HEAD_REQ_DW4_UNION unData; unData.strMemHead.b30AddrL = ulAddr >> 2; unData.strMemHead.b2AddrType = 0; printf("unData.strMemHead.b30AddrL=0x%x\r\n",unData.strMemHead.b30AddrL); printf("unData.strMemHead.b2AddrType=0x%x\r\n",unData.strMemHead.b2AddrType); printf("unData.aulValue[3]=0x%x\r\n",unData.aulValue[3]); // 0000 0000 0000 0001 0000 0010 0010 0100 printf("unData.ausValue[6]=0x%x\r\n",unData.ausValue[6]); // why get 0x0 instead of 0x1 ? printf("unData.ausValue[7]=0x%x\r\n",unData.ausValue[7]); return 0; } int main() { Test_func(0x10224); return 0; } Hi, For ARM64 big-endian, when compiled above code with -O0, the output of ausValue[6] is 0x1 which is correct, but when I try to compile with -O1 or -O2, the output of ausValue[6] is 0x0 which is wrong. Will appreciate if you can help me look into this issue? is this gcc bug?