From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6354F3858018; Thu, 4 Jan 2024 12:01:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6354F3858018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704369685; bh=6b7uxHKo4qdcZEsa5yogMykOLbwm2eh8MsSCVuhAJQ4=; h=From:To:Subject:Date:From; b=SPMnxG4S+aBKt/PzywYTMSWwApXFsrZPZGbunQUzOwl3v41HmJaQpIItBtbSxMbcK E/sW5XatXZmBrCpxG8lIa2ZHkrbyEEK7TBaIl8vufIBuFnf5gPi/9IqUg74MSVzenK B3h1Pj5GUR6VMUINsHToxgHqAqVtEY3B0l+F1fN4= From: "jwzeng at nuaa dot edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/113232] New: wrong code at -fpack-struct on x86_64-pc-linux-gnu Date: Thu, 04 Jan 2024 12:01:24 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jwzeng at nuaa dot edu.cn 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=3D113232 Bug ID: 113232 Summary: wrong code at -fpack-struct on x86_64-pc-linux-gnu Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jwzeng at nuaa dot edu.cn Target Milestone: --- I compiled the following code with gcc at -fpack-struct, and it produces the wrong code.=20 The correct output result should be 0, but 2048 was output under -fpack-str= uct.=20 This bug seems to be a long-standing bug that exists on almost all gcc versions. Compiler explorer: https://godbolt.org/z/v4sq988P9 ```c $ cat test.c int printf(const char *, ...); struct a { char b; short c; }; union { short b; struct a d; } e; int main() { e.b =3D 0; for (e.d.c =3D 0; e.d.c < 8; e.d.c++) ;=20=20 printf("%d\n", e.b); } $ $ gcc-tk test.c -O0; ./test.c 0 $ gcc-tk test.c -fpack-struct; ./test.c 2048 $ ccomp test.c -O0; ./a.out 0 $ $ gcc-tk --version gcc (GCC) 13.1.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ $ ccomp --version The CompCert C verified compiler, version 3.12 ```=