From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2B7243845BEE; Tue, 28 Nov 2023 17:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B7243845BEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701193381; bh=go8gb7fct/QX3hJHWO0JfpdyvU99PBCtEkxT2MtvY9U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=g8Pptnm1R0yiy9pnYrTGbIa9afBbd+VGZjWpsK1iR48OGTqQ10x8WUTiW4C9OedLB Tw+TLeeVO8B6vnIH2xoDH7gkL2jAXsGlZZOBxOUKp6JdTvRn18y4bQYiFpclvOjpNt MSHy/RrLIveOZ5++D1RRWjA5d0JPfKKU0Bm0RgtE= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112733] [14 Regression] ICE: Segmentation fault in wide-int.cc during GIMPLE pass: sccp Date: Tue, 28 Nov 2023 17:43:00 +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: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created 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=3D112733 --- Comment #11 from Jakub Jelinek --- Created attachment 56707 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56707&action=3Dedit gcc14-pr112733-2.patch Second patch to be tested. Turned out it is more complicated than that. If n > m, i.e. when divisor in absolute value is larger than dividend, we w= ant divmod_internal_2 to know that, such that e.g. it skips the main loop and l= ooks at correct most significant half limb of the divisor, but the if (s) for (i =3D 0; i < n; i++) b_remainder[i] =3D (b_dividend[i] >> s) | (b_dividend[i+1] << (HOST_BITS_PER_HALF_WIDE_INT - s)); else for (i =3D 0; i < n; i++) b_remainder[i] =3D b_dividend[i]; loops in such case already may invoke UB, because they copy stuff from b_dividend which just isn't there, at best some random upper bits, at worst crash. We can't copy more than there is in the array and need to tell the caller how much we've initialized, so that wi_pack can take it into account. While looking into this, I've noticed that I've allocated in case of XALLOC= AVEC multiplication and division/remainder calculations twice or 4 times as much as really needed, so this patch fixes that too.=