From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D0BF3385663A; Tue, 6 Jun 2023 12:00:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0BF3385663A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686052834; bh=zxEMS/ulYinfldpNbrzbc27F8kquGFO9ACjTufP/Qi0=; h=From:To:Subject:Date:From; b=JI5vVwjfXQWp7rMNnIlgQIn75cSmcf7GJud82o6+gdIhtF9YU+RDc14Ih9Bncoq9H hVpc2tmmyJMerY79oZYE9SqsAL+IdCioPi4/uBmkP7YYLu/5Sf3b7x/5JmZ2FIsqoY JwnlPATZwCrKq0/s+jFmOFarhEVVfMHH7b1c3BPM= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110141] New: Wrong code at -O2 on x86_64-linux-gnu Date: Tue, 06 Jun 2023 12:00: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: 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=3D110141 Bug ID: 110141 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: --- For the following code, gcc since 12 emits the wrong code at -O2. Compiler explorer: https://godbolt.org/z/reGo6jqGK $ cat a.c int printf(const char *, ...); int h, i =3D 1, m; int *j =3D &i, *k =3D &i, *l; short n(short b, short c, int d) { short e[] =3D {71, c, c, 40, 28, 57, 3, 8, 79, 19, c}; int f =3D d, a =3D b; short *g =3D e; while (f > 1) { a +=3D *g++; f -=3D 2; } a +=3D *g -=3D 255; return a; } int fn2() { h =3D 0; for (;; h =3D 5) { int o[4]; m =3D 0; for (; m < 4; m++) o[n(6, 7, 19) - 70 + m] =3D 6; if (h) { for (;;) { int p =3D 0; if (*k) break; l =3D &p; } *j =3D o[0]; return 0; } } } int main() { fn2(); printf("%d\n", i); } $ $ gcc-tk -O0 a.c && ./a.out 6 $ gcc-tk -O2 a.c && ./a.out 0 $=