From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 76F7639450EE; Mon, 22 Feb 2021 17:03:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76F7639450EE From: "zhan3299 at purdue dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99207] New: #pragma pack(1) and __int128 lead to bad optimization under O2 and higher optimization Date: Mon, 22 Feb 2021 17:03:00 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zhan3299 at purdue dot edu 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: Mon, 22 Feb 2021 17:03:00 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99207 Bug ID: 99207 Summary: #pragma pack(1) and __int128 lead to bad optimization under O2 and higher optimization Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zhan3299 at purdue dot edu Target Milestone: --- Following code behaves differently with different optimizations. $ cat test.c #pragma pack(1) struct { char a; __int128 b; } c; __int128 *d =3D &c.b; int main() { *d =3D 0; } In short, with O2 and higher optimization, gcc tries to use xmm register to initialize *d. However, as #pragma pack(1) enforces a different alignments,= xmm operation will trigger a segment fault. O0 (program returns 0): https://godbolt.org/z/nc997z O1 (program returns 0): https://godbolt.org/z/GqGfnf O2 (program returns 139): https://godbolt.org/z/4PWKMo O3 (program returns 139): https://godbolt.org/z/Y81sKK Os (program returns 139): https://godbolt.org/z/M3KGnh With asan, we can get: https://godbolt.org/z/34oW7e AddressSanitizer:DEADLYSIGNAL =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D1=3D=3DERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004= 010ae bp 0x000000000000 sp 0x7ffd361619b8 T0) =3D=3D1=3D=3DThe signal is caused by a READ memory access. =3D=3D1=3D=3DHint: this fault was caused by a dereference of a high value a= ddress (see register values below). Dissassemble the provided pc to learn which regist= er was used. #0 0x4010ae in main example.c:10 #1 0x7f8c4b3b60b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) #2 0x40111d in _start (/app/output.s+0x40111d) AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV example.c:10 in main =3D=3D1=3D=3DABORTING=