From patchwork Mon Sep 26 14:36:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1524749wrt; Mon, 26 Sep 2022 07:37:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HgKWoMJgTdF6Jck2xNx/4JyekoP1k8rm/C9FHDvC/5y03DIH6CAL5ciGaYKW8nmwPzm/p X-Received: by 2002:a17:907:2cf3:b0:77d:89da:499c with SMTP id hz19-20020a1709072cf300b0077d89da499cmr17631281ejc.694.1664203042794; Mon, 26 Sep 2022 07:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664203042; cv=none; d=google.com; s=arc-20160816; b=d1r5pPMGE1HxwdAe1yNhVVEBL5xFsPggjH7lQVjdKB+tglPMygD92Tj1KFgzYx1WQJ +HWRPM7exCa/1uUFlMJpOb5RNEHPxn1anEuqOqlLOyYVan2WfjyUQymb/4spuAUPHrlk 9TZci8YPwKoxEXYwOqDIIV0zrWLoZeuip/sQwIqL295dA7mbsbx9utMJ0r782/K5FIdT R8Ja+desUsgGSj9OrMTYs8vJckZK2MIq6y8weLwIe5kjbC9Ef8UDkzDDBNhhQvMA6sm7 4rjITPlBM+GeYLi86z1X+q3gcg2DbsL7iHiboRaM4LDmuub/AoQH/vWGuX5WD7sWvCA0 VEvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=QmXmOaYEOru6jcSLFTNmKMoF+58x23L58NatHFeinCE=; b=YeZidz0C20SDodem+H3KwB1IMPr2nHmHzB5ple0rRjipdFgpZu/YIn5HRv9O+1P9jv pOEUQRIsk6IDSSrlM3XC+YCDSrVWbnnNaTTsx7fmZyS3m8xYGW1yOXLNaNeMZZgDyQlw gsa66D2DtQd2eXs6cBhcZp6aXaWeqPJMVZ1BmxEDjvpJXo2LfXnOWKq6z1F3mUTyr2we EhBfmR068Djb2JV8HbYvggGxaHD0TWrTbMJoaFZsABfd5pb04dRLkVkjhTrywyDeni2D RzlKWOj51HVXm8bdi9b3CLDswx5dr2KMxmaL2qo062UistIsFBSVgUQQmq3Yce6nPyCO 5E7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jSW7NG4W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h15-20020a170906398f00b007413b206b16si14313293eje.843.2022.09.26.07.37.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 07:37:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jSW7NG4W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DD6B3858C00 for ; Mon, 26 Sep 2022 14:37:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DD6B3858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664203034; bh=QmXmOaYEOru6jcSLFTNmKMoF+58x23L58NatHFeinCE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jSW7NG4WUcqdnjMwFd0xobK5vgfphPMT9PNiIQPwK5didk/s8q9k61W/Xi5Qiv/aL WhNJl86UJ9hcvu/NECzYs9kp55+xFOl3tO3RiUj05S+kLW313wwbTT6rijKc1nQbZu ysOtt+HYKa/FfaWmFG4A4xbGo5+4mQ6JEZC/cC+s= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3F58B3858287 for ; Mon, 26 Sep 2022 14:36:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F58B3858287 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-39-GEheIYiyNkuettkrj3hkbg-1; Mon, 26 Sep 2022 10:36:25 -0400 X-MC-Unique: GEheIYiyNkuettkrj3hkbg-1 Received: by mail-qt1-f200.google.com with SMTP id g6-20020ac84b66000000b0035cf832dec9so4826902qts.6 for ; Mon, 26 Sep 2022 07:36:25 -0700 (PDT) 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; bh=QmXmOaYEOru6jcSLFTNmKMoF+58x23L58NatHFeinCE=; b=Tvq9uRZRW1Xt4vkgJYj4gJ47wfUwdAl5WJDL97Ysqi3Dn/yqj0j88pL0FOXWnXasZM TvJYTKhKH2FHOYIR53EHRJOYYeV/gqXIckl7C8EJmVEr7h/3thMSr3xZpAvKUd0T9H35 hX6KvdoXA6Kiy0MedEIJMzPqxmL4S5KEF2DiCl51iH2rp39Zwk5waTTCvfOHrcft2Thd t25Z4RkICRK+CR3kVay/10pKXwmpeUMgdwtib9VvxclhMD6rg9j3mELuqJBZZUa5qEHt eCDI/2+lUJD9iT2STFymRYYDLrgIB6qZI2WObQZzmwO7j2E5YIHk2IIi5LorkNmdeic/ k+ag== X-Gm-Message-State: ACrzQf1K2YJml75By8ux+4HiyGysEd0oDZEPwE654OYnLIyYAZ3JxX4v /04WBXzku/cuXmxXwNBkyyTFgUqH+w+uORUnVI3Sxc4cPdoKY2wQcY5BjlbcNFZ+Rul2r0PtajI IMCnJCybGUyP1zylFjg5z3Br28rjSmPNUxkxfS9RtqRbh5R9QslE8nCF83BZeOaSNt6U= X-Received: by 2002:a05:620a:254f:b0:6bb:dcb6:4279 with SMTP id s15-20020a05620a254f00b006bbdcb64279mr14464785qko.79.1664202983679; Mon, 26 Sep 2022 07:36:23 -0700 (PDT) X-Received: by 2002:a05:620a:254f:b0:6bb:dcb6:4279 with SMTP id s15-20020a05620a254f00b006bbdcb64279mr14464760qko.79.1664202983273; Mon, 26 Sep 2022 07:36:23 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id fy27-20020a05622a5a1b00b0035d1f846b91sm6644509qtb.64.2022.09.26.07.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 07:36:22 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: variable template partial spec fixes [PR107033] Date: Mon, 26 Sep 2022 10:36:20 -0400 Message-Id: <20220926143620.24037-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc1.2.g4b79ee4b0c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.4 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_LOW, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: nathan@acm.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745043369574827103?= X-GMAIL-MSGID: =?utf-8?q?1745043369574827103?= In r13-2775-g32d8123cd6ce87 I overlooked that we need to adjust the call to add_mergeable_specialization in the MK_partial case to correctly handle variable template partial specializations (it currently assumes we're always dealing with one for a class template). This fixes an ICE when converting the testcase from that commit to use an importable header instead of a named module. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/107033 gcc/cp/ChangeLog: * module.cc (trees_in::decl_value): In the MK_partial case for a variable template partial specialization, pass decl_p=true to add_mergeable_specialization and set spec to the VAR_DECL not the TEMPLATE_DECL. * pt.cc (add_mergeable_specialization): For a variable template partial specialization, set the TREE_TYPE of the new DECL_TEMPLATE_SPECIALIZATIONS node to the TREE_TYPE of the VAR_DECL not the VAR_DECL itself. gcc/testsuite/ChangeLog: * g++.dg/modules/partial-2.cc, g++.dg/modules/partial-2.h: New files, factored out from ... * g++.dg/modules/partial-2_a.C, g++.dg/modules/partial-2_b.C: ... here. * g++.dg/modules/partial-2_c.H: New test. * g++.dg/modules/partial-2_d.C: New test. --- gcc/cp/module.cc | 17 ++++++---- gcc/cp/pt.cc | 2 +- gcc/testsuite/g++.dg/modules/partial-2.cc | 17 ++++++++++ gcc/testsuite/g++.dg/modules/partial-2.h | 38 +++++++++++++++++++++ gcc/testsuite/g++.dg/modules/partial-2_a.C | 39 +--------------------- gcc/testsuite/g++.dg/modules/partial-2_b.C | 18 +--------- gcc/testsuite/g++.dg/modules/partial-2_c.H | 5 +++ gcc/testsuite/g++.dg/modules/partial-2_d.C | 8 +++++ 8 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/partial-2.cc create mode 100644 gcc/testsuite/g++.dg/modules/partial-2.h create mode 100644 gcc/testsuite/g++.dg/modules/partial-2_c.H create mode 100644 gcc/testsuite/g++.dg/modules/partial-2_d.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f23832cb56a..7496df5e843 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -8185,13 +8185,18 @@ trees_in::decl_value () /* Set the TEMPLATE_DECL's type. */ TREE_TYPE (decl) = TREE_TYPE (inner); - if (mk & MK_template_mask - || mk == MK_partial) + /* Add to specialization tables now that constraints etc are + added. */ + if (mk == MK_partial) { - /* Add to specialization tables now that constraints etc are - added. */ - bool is_type = mk == MK_partial || !(mk & MK_tmpl_decl_mask); - + bool is_type = TREE_CODE (inner) == TYPE_DECL; + spec.spec = is_type ? type : inner; + add_mergeable_specialization (!is_type, false, + &spec, decl, spec_flags); + } + else if (mk & MK_template_mask) + { + bool is_type = !(mk & MK_tmpl_decl_mask); spec.spec = is_type ? type : mk & MK_tmpl_tmpl_mask ? inner : decl; add_mergeable_specialization (!is_type, !is_type && mk & MK_tmpl_alias_mask, diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index db4e808adec..1f088fe281e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -31010,7 +31010,7 @@ add_mergeable_specialization (bool decl_p, bool alias_p, spec_entry *elt, /* A partial specialization. */ tree cons = tree_cons (elt->args, decl, DECL_TEMPLATE_SPECIALIZATIONS (elt->tmpl)); - TREE_TYPE (cons) = elt->spec; + TREE_TYPE (cons) = decl_p ? TREE_TYPE (elt->spec) : elt->spec; DECL_TEMPLATE_SPECIALIZATIONS (elt->tmpl) = cons; } } diff --git a/gcc/testsuite/g++.dg/modules/partial-2.cc b/gcc/testsuite/g++.dg/modules/partial-2.cc new file mode 100644 index 00000000000..1316bf5e1c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/partial-2.cc @@ -0,0 +1,17 @@ +static_assert(is_reference_v); +static_assert(is_reference_v); +static_assert(!is_reference_v); + +static_assert(A::is_reference_v); +static_assert(A::is_reference_v); +static_assert(!A::is_reference_v); + +#if __cpp_concepts +static_assert(concepts::is_reference_v); +static_assert(concepts::is_reference_v); +static_assert(!concepts::is_reference_v); + +static_assert(concepts::A::is_reference_v); +static_assert(concepts::A::is_reference_v); +static_assert(!concepts::A::is_reference_v); +#endif diff --git a/gcc/testsuite/g++.dg/modules/partial-2.h b/gcc/testsuite/g++.dg/modules/partial-2.h new file mode 100644 index 00000000000..afcfce791b3 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/partial-2.h @@ -0,0 +1,38 @@ +template constexpr bool is_reference_v = false; +template constexpr bool is_reference_v = true; +template constexpr bool is_reference_v = true; + +struct A { + template static constexpr bool is_reference_v = false; +}; + +template constexpr bool A::is_reference_v = true; +template constexpr bool A::is_reference_v = true; + +#if __cpp_concepts +namespace concepts { + template bool is_reference_v; + + template requires __is_same(T, T&) + constexpr bool is_reference_v = true; + + template requires __is_same(T, T&&) && (!__is_same(T, T&)) + constexpr bool is_reference_v = true; + + template requires (!__is_same(T, T&)) && (!__is_same(T, T&&)) + constexpr bool is_reference_v = false; + + struct A { + template static bool is_reference_v; + }; + + template requires __is_same(T, T&) + constexpr bool A::is_reference_v = true; + + template requires __is_same(T, T&&) && (!__is_same(T, T&)) + constexpr bool A::is_reference_v = true; + + template requires (!__is_same(T, T&)) && (!__is_same(T, T&&)) + constexpr bool A::is_reference_v = false; +} +#endif diff --git a/gcc/testsuite/g++.dg/modules/partial-2_a.C b/gcc/testsuite/g++.dg/modules/partial-2_a.C index 2681bb59ce8..1582f56f2d4 100644 --- a/gcc/testsuite/g++.dg/modules/partial-2_a.C +++ b/gcc/testsuite/g++.dg/modules/partial-2_a.C @@ -3,41 +3,4 @@ // { dg-module-cmi pr106826 } export module pr106826; -template constexpr bool is_reference_v = false; -template constexpr bool is_reference_v = true; -template constexpr bool is_reference_v = true; - -struct A { - template static constexpr bool is_reference_v = false; -}; - -template constexpr bool A::is_reference_v = true; -template constexpr bool A::is_reference_v = true; - -#if __cpp_concepts -namespace concepts { - template bool is_reference_v; - - template requires __is_same(T, T&) - constexpr bool is_reference_v = true; - - template requires __is_same(T, T&&) && (!__is_same(T, T&)) - constexpr bool is_reference_v = true; - - template requires (!__is_same(T, T&)) && (!__is_same(T, T&&)) - constexpr bool is_reference_v = false; - - struct A { - template static bool is_reference_v; - }; - - template requires __is_same(T, T&) - constexpr bool A::is_reference_v = true; - - template requires __is_same(T, T&&) && (!__is_same(T, T&)) - constexpr bool A::is_reference_v = true; - - template requires (!__is_same(T, T&)) && (!__is_same(T, T&&)) - constexpr bool A::is_reference_v = false; -} -#endif +#include "partial-2.h" diff --git a/gcc/testsuite/g++.dg/modules/partial-2_b.C b/gcc/testsuite/g++.dg/modules/partial-2_b.C index 0af41ef5e5e..1b0c7a53e9f 100644 --- a/gcc/testsuite/g++.dg/modules/partial-2_b.C +++ b/gcc/testsuite/g++.dg/modules/partial-2_b.C @@ -2,20 +2,4 @@ // { dg-additional-options -fmodules-ts } module pr106826; -static_assert(is_reference_v); -static_assert(is_reference_v); -static_assert(!is_reference_v); - -static_assert(A::is_reference_v); -static_assert(A::is_reference_v); -static_assert(!A::is_reference_v); - -#if __cpp_concepts -static_assert(concepts::is_reference_v); -static_assert(concepts::is_reference_v); -static_assert(!concepts::is_reference_v); - -static_assert(concepts::A::is_reference_v); -static_assert(concepts::A::is_reference_v); -static_assert(!concepts::A::is_reference_v); -#endif +#include "partial-2.cc" diff --git a/gcc/testsuite/g++.dg/modules/partial-2_c.H b/gcc/testsuite/g++.dg/modules/partial-2_c.H new file mode 100644 index 00000000000..bd838529ce0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/partial-2_c.H @@ -0,0 +1,5 @@ +// PR c++/107033 +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +#include "partial-2.h" diff --git a/gcc/testsuite/g++.dg/modules/partial-2_d.C b/gcc/testsuite/g++.dg/modules/partial-2_d.C new file mode 100644 index 00000000000..ed54d3c2884 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/partial-2_d.C @@ -0,0 +1,8 @@ +// PR c++/107033 +// { dg-additional-options -fmodules-ts } +// { dg-module-cmi pr107033 } +export module pr107033; + +import "partial-2_c.H"; + +#include "partial-2.cc"