From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0DF6A386C5A6; Tue, 25 Jun 2024 06:37:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DF6A386C5A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1719297480; bh=SOi4f+RJrJtwY5P+GNInhCaxaxA6DdXM+LV+V+PtOP8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IgqaTAhaZZTwZ0q0NWsbiQMq/LQ9k/zeJ6ix6dIeiIJedlaM20iSAViIyIU83Ktk3 g2o755IhkCZbhWLl00K8D5bta0q6sLnioByIJCmZY88NjB9bZt9hLPfDjXKq5SZ6y2 QpWZsOo2XQ3F7afHRnLsaiM9mmveplhn+gNKG+Uc= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114930] [14/15 regression] ICE in fld_incomplete_type_of when building libwebp with -std=c23 -flto Date: Tue, 25 Jun 2024 06:37:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: ice-checking, 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: 14.2 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=3D114930 --- Comment #8 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:777cc6a01d1cf783a36d0fa67ab20f0312f35d7a commit r15-1597-g777cc6a01d1cf783a36d0fa67ab20f0312f35d7a Author: Jakub Jelinek Date: Tue Jun 25 08:35:56 2024 +0200 c: Fix ICE related to incomplete structures in C23 [PR114930] Here is a version of the c_update_type_canonical fixes which passed bootstrap/regtest. The non-trivial part is the handling of the case when build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x)) returns a type with NULL TYPE_CANONICAL. That should happen only if TYPE_CANONICAL (t) =3D=3D t, because otherwise c_update_type_canonic= al should have been already called on the other type. c, the returned type, is usually x and in that case it should have TYPE_CANONICAL set to itself, or worst for whatever reason x is not the right canonical type (say it has attributes or whatever disqualifies it from check_qualified_type). In that case either it finds some pre-existing type from the variant chain of t which is later in the chain and we haven't processed it yet (but then get_qualified_type moves it right after t in: /* Put the found variant at the head of the variant list so frequently searched variants get found faster. The C++ FE benefits greatly from this. */ tree t =3D *tp; *tp =3D TYPE_NEXT_VARIANT (t); TYPE_NEXT_VARIANT (t) =3D TYPE_NEXT_VARIANT (mv); TYPE_NEXT_VARIANT (mv) =3D t; return t; optimization), or creates a fresh new type using build_variant_type_cop= y, which again places the new type right after t: /* Add the new type to the chain of variants of TYPE. */ TYPE_NEXT_VARIANT (t) =3D TYPE_NEXT_VARIANT (m); TYPE_NEXT_VARIANT (m) =3D t; TYPE_MAIN_VARIANT (t) =3D m; At this point we want to make c its own canonical type (i.e. TYPE_CANON= ICAL (c) =3D c;), but also need to process pointers to it and only then retu= rn back to processing x. Processing the whole chain from c again could be cost= ly, we could have hundreds of types in the chain already processed, and whi= le the loop would just quickly skip them for (tree x =3D t, l =3D NULL_TREE; x; l =3D x, x =3D TYPE_NEXT_VARIA= NT (x)) { if (x !=3D t && TYPE_STRUCTURAL_EQUALITY_P (x)) ... else if (x !=3D t) continue; it feels costly. So, this patch instead moves c from right after t to right before x in the chain (that shouldn't change anything, because clearly build_qualified_type didn't find any matches in the chain before x) and continues processing the c at that position, so should handle the x that encountered this in the next iteration. We could avoid some of the moving in the chain if we processed the chain twice, once deal only with x !=3D t && TYPE_STRUCTURAL_EQUALITY_P (x) && TYPE_CANONICAL (t) =3D=3D t && check_qualified_type (t, x, TYPE_QUAL= S (x)) types (in that case set TYPE_CANONICAL (x) =3D x) and once the rest. T= here is still the theoretical case where build_qualified_type would return a new type and in that case we are back to the moving the type around a= nd needing to handle it though. 2024-06-25 Jakub Jelinek Martin Uecker PR c/114930 PR c/115502 gcc/c/ * c-decl.cc (c_update_type_canonical): Assert t is main variant with 0 TYPE_QUALS. Simplify and don't use check_qualified_type. Deal with the case where build_qualified_type returns TYPE_STRUCTURAL_EQUALITY_P type. gcc/testsuite/ * gcc.dg/pr114574-1.c: Require lto effective target. * gcc.dg/pr114574-2.c: Likewise. * gcc.dg/pr114930.c: New test. * gcc.dg/pr115502.c: New test.=