From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8F8163858C5F; Fri, 3 Feb 2023 20:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F8163858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675457985; bh=Cocb6EY3mkdD1NhcYlIdkcQ8TTBgPVWoeojF4/xf2qg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PWOMiX8znoH5LJmrzIfWWDC/jnSlV7VIGVv3HAI5bTY6w3HtNDHGy2lxtkzyF+d1G GYnikSpWRo5DWYfF/mgfcQDLptasP9mV0pcS6RmUjXSGBB3h/6MzpZ9bo3YTyxMVBX WMlYLyMbK+31s//ArNom9LpYpWfIiKPl3/ZiWbZU= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer Date: Fri, 03 Feb 2023 20:59:45 +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: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 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=3D107079 --- Comment #2 from Marek Polacek --- Very interesting. We're in store_init_value, initializing x with &TARGET_EXPR = }> but we must lifetime-extend via extend_ref_init_temps and we get _ZGR1x_.x =3D (const struct X *) & >>>;, (const = struct X &) &_ZGR1x_; Since x was declared constexpr, we do cxx_constant_init (not quiet) and we = hit the code added in r269003: + bool preeval =3D SCALAR_TYPE_P (type) || TREE_CODE (t) =3D=3D MODIFY_EXP= R; + if (preeval) + { + /* Evaluate the value to be stored without knowing what object it wi= ll be + stored in, so that any side-effects happen first. */ + if (!SCALAR_TYPE_P (type)) + new_ctx.ctor =3D new_ctx.object =3D NULL_TREE; + init =3D cxx_eval_constant_expression (&new_ctx, init, false, + non_constant_p, overflow_p); while evaluating the INIT_EXPR _ZGR1x_.x =3D (const struct X *) & >>>. But we have no ctx.ctor or ctx.object he= re so lookup_placeholder won't find anything and we ICE on 7861 /* A placeholder without a referent. We can get here when 7862 checking whether NSDMIs are noexcept, or in massage_init_elt; 7863 just say it's non-constant for now. */ 7864 gcc_assert (ctx->quiet); Somehow we should manage that the PLACEHOLDER_EXPR is replaced with _ZGR1x_= I guess.=