From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B7663858003; Sun, 15 Aug 2021 23:43:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B7663858003 From: "george.thopas at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/101925] New: reversed storage order when compiling with -O3 only Date: Sun, 15 Aug 2021 23:43:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: george.thopas at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 23:43:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101925 Bug ID: 101925 Summary: reversed storage order when compiling with -O3 only Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: george.thopas at gmail dot com Target Milestone: --- /* reversed storage order when compiling with -O3 only.=20 this time sets up an all big-endian struct=20 from an all little-endian one no warnings=20 Target: x86_64-pc-linux-gnu gcc versie 11.1.0 (Gentoo 11.1.0-r2 p3)=20 gcc-trunk too $ gcc -Wall -Wextra -O3 test.c=20 $ ./a.out=20 Abort=20 */ #define BIG_ENDIAN __attribute__((scalar_storage_order("big-endian"))) /* host order version (little endian)*/ struct _ip6_addr { union { char addr8[16]; int addr32[4]; } u; }; typedef struct _ip6_addr t_ip6_addr; struct _net_addr { char is_v4; union { int addr; t_ip6_addr addr6; } u; }; typedef struct _net_addr t_net_addr; /* big endian version */ struct _be_ip6_addr { union { char addr8[16]; } BIG_ENDIAN u; } BIG_ENDIAN; typedef struct _be_ip6_addr t_be_ip6_addr; struct _be_net_addr { char is_v4; union { t_be_ip6_addr addr6; int addr; } BIG_ENDIAN u; } BIG_ENDIAN; typedef struct _be_net_addr t_be_net_addr; /* convert */ t_be_ip6_addr be_ip6_addr(const t_ip6_addr ip6) { t_be_ip6_addr rc =3D { .u.addr8[0] =3D ip6.u.addr8[0], .u.addr8[1] =3D ip6.u.addr8[1], .u.addr8[2] =3D ip6.u.addr8[2], .u.addr8[3] =3D ip6.u.addr8[3], .u.addr8[4] =3D ip6.u.addr8[4], .u.addr8[5] =3D ip6.u.addr8[5], .u.addr8[6] =3D ip6.u.addr8[6], .u.addr8[7] =3D ip6.u.addr8[7], .u.addr8[8] =3D ip6.u.addr8[8], .u.addr8[9] =3D ip6.u.addr8[9], .u.addr8[10] =3D ip6.u.addr8[10], .u.addr8[11] =3D ip6.u.addr8[11], .u.addr8[12] =3D ip6.u.addr8[12], .u.addr8[13] =3D ip6.u.addr8[13], .u.addr8[14] =3D ip6.u.addr8[14], .u.addr8[15] =3D ip6.u.addr8[15], }; return rc; } t_be_net_addr be_net_addr(const t_net_addr ip) { t_be_net_addr rc =3D {.is_v4 =3D ip.is_v4 }; if (ip.is_v4) { rc.u.addr =3D ip.u.addr; } else { rc.u.addr6 =3D be_ip6_addr(ip.u.addr6); } return rc; } int main(void) { t_be_net_addr out =3D { }; t_net_addr in =3D { .is_v4 =3D 0, .u.addr6.u.addr8 =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } }; out =3D be_net_addr(in); // actually first 4 bytes are swapped if (in.u.addr6.u.addr8[0] !=3D out.u.addr6.u.addr8[0]) __builtin_abort(); return 0; }=