From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7CDF63858D1E; Thu, 7 Sep 2023 07:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CDF63858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694072320; bh=8xltdgA00C6P815jO4AjzCAdmzJfoUmmb4BPEx5vgWY=; h=From:To:Subject:Date:From; b=dS+YG1cOQpu2HdBqhA98m0OGfsAVBhhRFuPVKXOY/6oEbLNcTMRYPgD4mnyuRiQa2 ImGOfHjav3l3kkfoctm/5gsTqG+gq3vmoAIwxAVVNa4GieRXvtNuoIzTAu5LwNIMQB FLLKI4bLDwb5i9w7BhgCeJ9vk77O+OonllFUTgLo= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111319] New: Wrong code at -O2 on x86_64-linux-gnu Date: Thu, 07 Sep 2023 07:38:40 +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: shaohua.li at inf dot ethz.ch 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=3D111319 Bug ID: 111319 Summary: Wrong code at -O2 on x86_64-linux-gnu Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch Target Milestone: --- The executable produced by gcc -O2 would crash. Not sure if there is UB in = the code or not as `h` has not been dereferenced after `h--`. Compiler explorer: https://godbolt.org/z/avssssPze $ cat a.c int printf(const char *, ...); int a, b =3D 5, c, d; int e[2] =3D {0, 0}; int i() { int f =3D 0; int g[2] =3D {1, f}; int *h =3D g; h--; if (!b) while (h >=3D &c =3D=3D 1) h--; h++; d =3D *h; return d; } int main() { if (e[i()]) e[0] =3D 0; printf("%d\n", a); } $ $ gcc -O2 a.c && ./a.out Segmentation fault $=