From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 92C333858422; Fri, 19 Nov 2021 01:19:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92C333858422 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103314] [12 regression] ICE on valid code at -O1 and above on x86_64-linux-gnu: Segmentation fault since r12-5358 Date: Fri, 19 Nov 2021 01:19:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: Fri, 19 Nov 2021 01:19:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103314 --- Comment #5 from Andrew Pinski --- Simplified testcase: int main() { unsigned c =3D 0, d =3D c ? 1 ^ c ^ 1 >> (-1) : 0; return c; } The problem is we get: #3 0x0000000000b5aa2d in fold_binary_loc(unsigned int, tree_code, tree_nod= e*, tree_node*, tree_node*) () at /home/apinski/src/upstream-gcc/gcc/gcc/fold-const.c:10822 10822 tem =3D generic_simplify (loc, code, type, op0, op1); $1 =3D void (gdb) p debug_generic_expr(op0) (unsigned int) (1 >> -1) $2 =3D void (gdb) p debug_generic_expr(op1) 1 $3 =3D void (gdb) op code Undefined command: "op". Try "help". (gdb) p code $4 =3D BIT_XOR_EXPR Which we produce: (unsigned int) ((1 >> -1) ^ 1) But the code in fold_binary_loc comes a long and decides we should reassociative this and it just goes back and forth or deciding which is correct. So doing this instead: TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type) || (GIMPLE && TYPE_PRECISION (TREE_TYPE (@0)) =3D=3D TYPE_PRECIS= ION (type)) Fixes the problem and we should not run into the back and forth issue.=