Message ID | 20221207201827.1720474-1-ppalka@redhat.com |
---|---|
State | Committed |
Commit | a7c8036b26082d8da001e05596777c5f911590e1 |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C8AB388FB6E for <patchwork@sourceware.org>; Wed, 7 Dec 2022 20:19:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C8AB388FB6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670444341; bh=ke2aV9uUT1BPh+gfmIpT7GVHDGIh4x0B/O+KeQ8zS/Y=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=wSDf7r4tbHSmo7solCaQZSmdesbVhrWXXvihDJIT8g/6Zb/iXTLVNuKjjo3K/xhp7 QX6R2iFsWXFiiU0TVRr9KEpstAGhbK8PKeTk0pkytG92PdhmNz25hEeKjrZOQ1mjPh Xip5y3TdvPM1n+jexrU+HEx8KIaXT1L1tHLegFmw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D2DBA3833A3A for <gcc-patches@gcc.gnu.org>; Wed, 7 Dec 2022 20:18:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D2DBA3833A3A Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-48-LbU1NCePMzu2CY8Z37d8EA-1; Wed, 07 Dec 2022 15:18:31 -0500 X-MC-Unique: LbU1NCePMzu2CY8Z37d8EA-1 Received: by mail-qv1-f71.google.com with SMTP id jh2-20020a0562141fc200b004c74bbb0affso24872167qvb.21 for <gcc-patches@gcc.gnu.org>; Wed, 07 Dec 2022 12:18:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ke2aV9uUT1BPh+gfmIpT7GVHDGIh4x0B/O+KeQ8zS/Y=; b=qUpnrJLl5SPC6VHCjxk+zcln6jfHLk34chAsspwWCr89n0dQduqW5jrBPCu+Y1afq1 ng7xsYpYUy3ivlGUnMxBKV1qkGZuqhp4YHWt5afZ3mZe4oM2Ql+QOltFYterOkGYJPsR nkpgYg6mjlo3IMyc4bD3xBiG/grKrw4NFLIK1hHN0/EGAyg3Tk+mdrLunFMAWdn/W6El PPBVSadDhOthQA0SS4ywTIQ/4PVGCM5HS8ER3M/yhoUn4c5DesQ0+4gaE8wExXVKBN6Q wOPQdGGFh1Lfbhp/5fgSDUZ+Sv7aGHIT9tCbHPqNXXGQqL0FLyMyFLhlh1lkZECKJvyU aalg== X-Gm-Message-State: ANoB5pmDuaZMyuGBs43sQIKP2vzB1k+SZ7JrX8xv02YcgRq7daV5a8KA yTc2sh+SFUzt56oCysbcTb0b6eJeeHOui2zHlyhKYLAluU6XnN8GxKDkGxgLButf7Cjc7wD9iT7 JbsgHTFQsMPZuFw7hMELP/PDGR8VKRTukTzONabmbmNBNAc5MO0SOtJasr29DliI7UqA= X-Received: by 2002:ac8:714a:0:b0:3a6:8aa9:3b85 with SMTP id h10-20020ac8714a000000b003a68aa93b85mr31439977qtp.144.1670444310189; Wed, 07 Dec 2022 12:18:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FR7gWKB5I1vd/BYWMIQ65wSFqijGoNASKwX/IvkpDrW0n2qmdYhrFnM+3fW/+95RcD+Fz4Q== X-Received: by 2002:ac8:714a:0:b0:3a6:8aa9:3b85 with SMTP id h10-20020ac8714a000000b003a68aa93b85mr31439951qtp.144.1670444309872; Wed, 07 Dec 2022 12:18:29 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id r16-20020ae9d610000000b006e42a8e9f9bsm9473288qkk.121.2022.12.07.12.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:18:29 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka <ppalka@redhat.com> Subject: [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886] Date: Wed, 7 Dec 2022 15:18:27 -0500 Message-Id: <20221207201827.1720474-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.7 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: ICE with concepts TS multiple auto deduction [PR101886]
|
|
Commit Message
Patrick Palka
Dec. 7, 2022, 8:18 p.m. UTC
In extract_autos_r, we need to reset TYPE_CANONICAL for the template type parameter after adjusting its index, otherwise we end up with a comptypes ICE for the below testcase. Note that such in-place type adjustment isn't generallly safe to do since the type could be the TYPE_CANONICAL of another (unadjusted) type, but in this case the canonical auto (of some level and 0 index) is the first auto (of that level) that's created, and so any auto that we do end up adjusting can't be the canonical one. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/101886 gcc/cp/ChangeLog: * pt.cc (extract_autos_r): Reset TYPE_CANONICAL after adjusting the template type parameter's index. Simplify by using TEMPLATE_TYPE_IDX. Add some sanity checks. gcc/testsuite/ChangeLog: * g++.dg/concepts/auto5.C: New test. --- gcc/cp/pt.cc | 12 +++++++++--- gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C
Comments
On Wed, 7 Dec 2022, Patrick Palka wrote: > In extract_autos_r, we need to reset TYPE_CANONICAL for the template > type parameter after adjusting its index, otherwise we end up with a > comptypes ICE for the below testcase. Note that such in-place type > adjustment isn't generallly safe to do since the type could be the > TYPE_CANONICAL of another (unadjusted) type, but in this case the > canonical auto (of some level and 0 index) is the first auto (of that > level) that's created, and so any auto that we do end up adjusting can't > be the canonical one. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? Ping. FWIW this blocks the modules + std::source_location patch[1] because the make_auto() call it adds to cxx_init_decl_processing would otherwise cause us to ICE on the existing test g++.dg/concepts/auto1.C. [1]: https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608127.html > > PR c++/101886 > > gcc/cp/ChangeLog: > > * pt.cc (extract_autos_r): Reset TYPE_CANONICAL after > adjusting the template type parameter's index. Simplify > by using TEMPLATE_TYPE_IDX. Add some sanity checks. > > gcc/testsuite/ChangeLog: > > * g++.dg/concepts/auto5.C: New test. > --- > gcc/cp/pt.cc | 12 +++++++++--- > gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++ > 2 files changed, 18 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 24ed718ffbb..d05a49b1c11 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data) > { > /* All the autos were built with index 0; fix that up now. */ > tree *p = hash.find_slot (t, INSERT); > - unsigned idx; > + int idx; > if (*p) > /* If this is a repeated constrained-type-specifier, use the index we > chose before. */ > - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p)); > + idx = TEMPLATE_TYPE_IDX (*p); > else > { > /* Otherwise this is new, so use the current count. */ > *p = t; > idx = hash.elements () - 1; > } > - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx; > + if (idx != TEMPLATE_TYPE_IDX (t)) > + { > + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0); > + gcc_checking_assert (TYPE_CANONICAL (t) != t); > + TEMPLATE_TYPE_IDX (t) = idx; > + TYPE_CANONICAL (t) = canonical_type_parameter (t); > + } > } > > /* Always keep walking. */ > diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C > new file mode 100644 > index 00000000000..f1d653efd87 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/concepts/auto5.C > @@ -0,0 +1,9 @@ > +// PR c++/101886 > +// { dg-do compile { target c++17_only } } > +// { dg-options "-fconcepts-ts" } > + > +template<typename...> struct A { }; > + > +A<int, int> a; > +A<auto, auto> b1 = a; > +A<auto, auto> b2 = a; > -- > 2.39.0.rc2 > >
On 12/7/22 15:18, Patrick Palka wrote: > In extract_autos_r, we need to reset TYPE_CANONICAL for the template > type parameter after adjusting its index, otherwise we end up with a > comptypes ICE for the below testcase. Note that such in-place type > adjustment isn't generallly safe to do since the type could be the > TYPE_CANONICAL of another (unadjusted) type, but in this case the > canonical auto (of some level and 0 index) is the first auto (of that > level) that's created, and so any auto that we do end up adjusting can't > be the canonical one. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. > PR c++/101886 > > gcc/cp/ChangeLog: > > * pt.cc (extract_autos_r): Reset TYPE_CANONICAL after > adjusting the template type parameter's index. Simplify > by using TEMPLATE_TYPE_IDX. Add some sanity checks. > > gcc/testsuite/ChangeLog: > > * g++.dg/concepts/auto5.C: New test. > --- > gcc/cp/pt.cc | 12 +++++++++--- > gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++ > 2 files changed, 18 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 24ed718ffbb..d05a49b1c11 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data) > { > /* All the autos were built with index 0; fix that up now. */ > tree *p = hash.find_slot (t, INSERT); > - unsigned idx; > + int idx; > if (*p) > /* If this is a repeated constrained-type-specifier, use the index we > chose before. */ > - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p)); > + idx = TEMPLATE_TYPE_IDX (*p); > else > { > /* Otherwise this is new, so use the current count. */ > *p = t; > idx = hash.elements () - 1; > } > - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx; > + if (idx != TEMPLATE_TYPE_IDX (t)) > + { > + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0); > + gcc_checking_assert (TYPE_CANONICAL (t) != t); > + TEMPLATE_TYPE_IDX (t) = idx; > + TYPE_CANONICAL (t) = canonical_type_parameter (t); > + } > } > > /* Always keep walking. */ > diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C > new file mode 100644 > index 00000000000..f1d653efd87 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/concepts/auto5.C > @@ -0,0 +1,9 @@ > +// PR c++/101886 > +// { dg-do compile { target c++17_only } } > +// { dg-options "-fconcepts-ts" } > + > +template<typename...> struct A { }; > + > +A<int, int> a; > +A<auto, auto> b1 = a; > +A<auto, auto> b2 = a;
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 24ed718ffbb..d05a49b1c11 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data) { /* All the autos were built with index 0; fix that up now. */ tree *p = hash.find_slot (t, INSERT); - unsigned idx; + int idx; if (*p) /* If this is a repeated constrained-type-specifier, use the index we chose before. */ - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p)); + idx = TEMPLATE_TYPE_IDX (*p); else { /* Otherwise this is new, so use the current count. */ *p = t; idx = hash.elements () - 1; } - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx; + if (idx != TEMPLATE_TYPE_IDX (t)) + { + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0); + gcc_checking_assert (TYPE_CANONICAL (t) != t); + TEMPLATE_TYPE_IDX (t) = idx; + TYPE_CANONICAL (t) = canonical_type_parameter (t); + } } /* Always keep walking. */ diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C new file mode 100644 index 00000000000..f1d653efd87 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto5.C @@ -0,0 +1,9 @@ +// PR c++/101886 +// { dg-do compile { target c++17_only } } +// { dg-options "-fconcepts-ts" } + +template<typename...> struct A { }; + +A<int, int> a; +A<auto, auto> b1 = a; +A<auto, auto> b2 = a;