From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0A10E3858CDA; Wed, 1 Feb 2023 09:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A10E3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675242638; bh=oz8hOXejD1RszoMCPrAl52hBbbB5aN+65vMs4tD80lc=; h=From:To:Subject:Date:From; b=Ml4oMfTiaqH4XLIhawexQ012Y/5TIPkzKi2Y95gLxQgfo4u3UqEx0rsS97MPpjz14 wV6iUZPEHz/9WXcHyk/d4Z/i1WfPzXU/+izTEjdhNWD4Tx423TIOha8uojVV/akr38 5miMH0So21XGXUWQv60zCwHDj4Kh9fsAFaxxpGU0= From: "kristerw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108625] New: forwprop introduces new UB Date: Wed, 01 Feb 2023 09:10:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kristerw at gcc dot gnu.org 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=3D108625 Bug ID: 108625 Summary: forwprop introduces new UB Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- Consider the function unsigned char foo(int x) { int t =3D -x; unsigned char t1 =3D t; unsigned char t2 =3D t; return t1 + t2; } This does not invoke undefined behavior when called as foo(0x40000001), but forwprop1 optimizes this to unsigned char foo (int x) { int t; unsigned char _5; int _7; : t_2 =3D -x_1(D); _7 =3D t_2 - x_1(D); _5 =3D (unsigned char) _7; return _5; } where _7 has signed overflow for x =3D 0x40000001.=