From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D69E23858D32; Mon, 9 Oct 2023 17:19:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D69E23858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696871962; bh=GI3Cn2ysM2mrs2wAlG1tH7Z14iP3Z62Kp1TkKr6gyJo=; h=From:To:Subject:Date:From; b=crWfYKllbb0mp63v1c312H2tF5S/KMVFAuj92rV0RkPmQeTCdarUJxbnH112yT3if ZC11hQCO9inT49Whe1WF7y0I00JyFrERjm23ZdkmeYKALTdIuuQTkxHspU+qDeZ/A/ cTLs+NW6dZpeEk1xIO0SQH9aThRbh3rIN/S5bKNc= From: "cuzdav at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111742] New: Misaligned generated code with MI using aligned virtual base Date: Mon, 09 Oct 2023 17:19:21 +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: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cuzdav 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111742 Bug ID: 111742 Summary: Misaligned generated code with MI using aligned virtual base Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cuzdav at gmail dot com Target Milestone: --- Generated code is misaligned (and crashes in slightly more complex code), in trunk all the way back to gcc 8.1, when built in c++11 or higher, with O3.= =20 (Linux, x86) Complete code: ////////////////////////////////////////// struct X { void * a =3D nullptr; void * b =3D nullptr; }; struct alignas(16) AlignedData { }; struct A : virtual AlignedData { X xxx; }; struct B : virtual AlignedData {}; struct Test : B, A {}; Test* t =3D new Test; int main() {} ////////////////////////////////////////// Compiler Explorer demo: https://godbolt.org/z/aodTdaedW Running with UB-san reports this: /app/example.cpp:14:8: runtime error: constructor call on misaligned address 0x00000227f2b8 for type 'struct A', which requires 16 byte alignment 0x00000227f2b8: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00= 00 00 00 00 00 00 00 00 ^=20 /app/example.cpp:8:8: runtime error: member access within misaligned address 0x00000227f2b8 for type 'struct A', which requires 16 byte alignment 0x00000227f2b8: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00= 00 00 00 00 00 00 00 00 ^=