From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 32D5E3858408; Mon, 26 Feb 2024 09:09:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32D5E3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708938576; bh=hHYECbPD7AQTL5NTW2KO3fGRC6GRQ3sFNWS/FZXqR1c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UH6IV9N54zyZMlTAmPwkgbp/SMi7OQmJM9JReYkyRgK4yoaHgtHDbg16j1kl1byuN gkP8ZTpMG8LFdU6LLKcXBtVChtHjoqyZCc5/ImuTfd6vWRLDqaMECxoEIvjO4y3OuZ WolWjJ0CTEXs6RuQ57mCe5BIknRg2TrgZgSrO1oo= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114084] ICE: SIGSEGV: infinite recursion in fold_build2_loc / fold_binary_loc with _BitInt(127) Date: Mon, 26 Feb 2024 09:09:33 +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: 14.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114084 --- Comment #7 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:f9d2a95be5680e04f53141c2675798b06d23f409 commit r14-9174-gf9d2a95be5680e04f53141c2675798b06d23f409 Author: Jakub Jelinek Date: Mon Feb 26 10:07:39 2024 +0100 fold-const: Avoid infinite recursion in +-*&|^minmax reassociation [PR114084] In the following testcase we infinitely recurse during BIT_IOR_EXPR reassociation. One operand is (unsigned _BitInt(31)) a << 4 and another operand 2147483647 >> 1 | 80 where both the right shift and the | 80 trees have TREE_CONSTANT set, but weren't folded because of delayed folding, where some foldings are apparently done even in that case unfortunately. Now, the fold_binary_loc reassocation code splits both operands into variable part, minus variable part, constant part, minus constant part, literal part and minus literal parts, to prevent infinite recursion punts if there are just 2 parts altogether from the 2 operands and then goes on with reassociation, merges first the corresponding parts from both operands and then some further merges. The problem with the above expressions is that we get 3 different objec= ts, var0 (the left shift), con1 (the right shift) and lit1 (80), so the infinite recursion prevention doesn't trigger, and we eventually merge con1 with lit1, which effectively reconstructs the original op1 and then associate that with var0 which is original op0, and associate_trees for that case calls fold_binary. There are some casts involved there too (the T type= def type and the underlying _BitInt type which are stripped with STRIP_NOPS= ). The following patch attempts to prevent this infinite recursion by trac= king the origin (if certain var comes from nothing - 0, op0 - 1, op1 - 2 or = both - 3) and propagates it through all the associate_tree calls which merge the vars. If near the end we'd try to merge what comes solely from op0 with what comes solely from op1 (or vice versa), the patch punts, because then it isn't= any kind of reassociation between the two operands, if anything it should be handled when folding the suboperands. 2024-02-26 Jakub Jelinek PR middle-end/114084 * fold-const.cc (fold_binary_loc): Avoid the final associate_tr= ees if all subtrees of var0 come from one of the op0 or op1 operands and all subtrees of con0 come from the other one. Don't clear variables which are never used afterwards. * gcc.dg/bitint-94.c: New test.=