From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1A2CA3858D37 for ; Thu, 27 Apr 2023 21:23:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A2CA3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682630586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=poUfwp55zWNOEvtjUo2NiE8YczHBMB9Q397OGGMmfCk=; b=JnY/BJHrU3orsY2qfgH9wAIu15CPMOmCP2Ou/l90sLn3aQpNM3kB/Cx6eZ1rgdrxoNzD5m dEIwG8lY1v4h/b48WPtisGjNF1rD292aStbZXG7Nbut9M4eQ8nHDL7eyz2hp+aGDeeBl3e erZ1Go0tS7olB5QUjh9yVS722CJPYlE= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-wrC3c2C6MQeemJ63YMo7jA-1; Thu, 27 Apr 2023 17:23:05 -0400 X-MC-Unique: wrC3c2C6MQeemJ63YMo7jA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2a7af0cb32aso43270501fa.0 for ; Thu, 27 Apr 2023 14:23:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682630584; x=1685222584; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=poUfwp55zWNOEvtjUo2NiE8YczHBMB9Q397OGGMmfCk=; b=evZowXNsVv3syoDbe0RLjxwl8i89mfdD2B6pCBYG9UGNl9KymqiKZhEtisqzzx2xnN XrjJrJn0g0wySnqdbLOG6wecf1pMZEGszfsg7W1eEEzpMt2XyMwQ38H7jMw/FHz5rhpy telYMXYmYPSTBddChbYoB9ED6uFmyxlrK8BSRAkp51pnkv+FxmqF0pwEfrYdUQ4BGWOs KNIPzjQxZ40FEDV6i95uPZAx1cAzWONJyLo0PqMxZwmzcUrdmLaWeIS+0f9vSyPMj7el iyHlsREbindXW5YCX4ycF1esW2ht1YgW0HV4F1CjLrF1pzKnpOOg7OoS0cnnAgQmK4G/ JEuA== X-Gm-Message-State: AC+VfDzu21l54RCstzNivdu5XeaUkPVV38YbODgFUMeCB7c3WUx+74m8 ZgM1YX8YDYupjxixlQeBl5mTrM2D6+Y/I1ckHDsMKbt/En0+dlZJgNbFzt3FrTp42RPI4APZSyM 5n6Nlw/rP55e4gX21kFtfL1omCy+NgDe4wiHlQ2pLxw== X-Received: by 2002:a05:651c:146:b0:2a8:c4d0:b135 with SMTP id c6-20020a05651c014600b002a8c4d0b135mr908094ljd.49.1682630583805; Thu, 27 Apr 2023 14:23:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69d2O647+BbD0BfL0dopViRTOX6yazbFnzudPMkQKvdLbItlpoFhlBCchkvaUUVbRbAQcSg7UI5Xw3C98TrwM= X-Received: by 2002:a05:651c:146:b0:2a8:c4d0:b135 with SMTP id c6-20020a05651c014600b002a8c4d0b135mr908088ljd.49.1682630583435; Thu, 27 Apr 2023 14:23:03 -0700 (PDT) MIME-Version: 1.0 References: <20230427204610.3403840-1-ppalka@redhat.com> In-Reply-To: <20230427204610.3403840-1-ppalka@redhat.com> From: Patrick Palka Date: Thu, 27 Apr 2023 17:22:52 -0400 Message-ID: Subject: Re: [PATCH] c++: outer args for level-lowered ttp [PR109651] To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Apr 27, 2023 at 4:46=E2=80=AFPM Patrick Palka w= rote: > > Now that with r14-11-g2245459c85a3f4 made us coerce the template > arguments of a bound ttp again after level-lowering, this unfortunately > causes a crash from coerce_template_args_for_ttp in the below testcase. > > During the level-lowering substitution T=3Dint into the bound ttp TT > as part of substitution into the lambda signature, current_template_parms > is just U=3DU rather than the ideal TT=3DTT, U=3DU. And because we don't > consistently set DECL_CONTEXT for level-lowered ttps (it's kind of a > chicken of the egg problem in this case), we attempt to use > current_template_parms to obtain the outer arguments during > coerce_template_args_for_ttp. But the depth 1 of c_t_p > current_template_parms is less than the depth 2 of the level-lowered TT, > and we end up segfaulting from there. > > So for level-lowered ttps it seems we need to get the outer arguments a > different way -- namely, we can look at the trailing parms of its > DECL_TEMPLATE_PARMS. Note this is not an ideal solution because TREE_CHAIN of DECL_TEMPLATE_PARMS in this case is just "2 , 1 U", so we're missing tparm information for the level that the ttp belongs to :/ So the only difference compared to using current_template_parms in this case is the extra empty level of args corresponding to the ttp's level. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/13? > > PR c++/109651 > > gcc/cp/ChangeLog: > > * pt.cc (coerce_template_args_for_ttp): For level-lowered > ttps with DECL_CONTEXT not set, obtain the outer template > arguments via its DECL_TEMPLATE_PARMS. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/ttp37.C: New test. > --- > gcc/cp/pt.cc | 5 +++++ > gcc/testsuite/g++.dg/template/ttp37.C | 11 +++++++++++ > 2 files changed, 16 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/template/ttp37.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 678cb7930e3..bbde61061f6 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -7872,6 +7872,11 @@ coerce_template_args_for_ttp (tree templ, tree arg= list, > tree outer =3D DECL_CONTEXT (templ); > if (outer) > outer =3D generic_targs_for (outer); > + else if (TEMPLATE_TYPE_LEVEL (TREE_TYPE (templ)) > + !=3D TEMPLATE_TYPE_ORIG_LEVEL (TREE_TYPE (templ))) > + /* This is a level-lowered template template parameter, for which > + we don't consistently set DECL_CONTEXT (FIXME). */ > + outer =3D template_parms_to_args (TREE_CHAIN (DECL_TEMPLATE_PARMS (t= empl))); > else if (current_template_parms) > { > /* This is an argument of the current template, so we haven't set > diff --git a/gcc/testsuite/g++.dg/template/ttp37.C b/gcc/testsuite/g++.dg= /template/ttp37.C > new file mode 100644 > index 00000000000..876e5b6232a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/ttp37.C > @@ -0,0 +1,11 @@ > +// PR c++/109651 > +// { dg-do compile { target c++20 } } > + > +template > +void f() { > + []() { > + [] class TT>(TT) { }; > + }; > +} > + > +template void f(); > -- > 2.40.1.423.g2807bd2c10 >