Message ID | 20220915201627.2942314-1-ppalka@redhat.com |
---|---|
State | New |
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 27EE5383A218 for <patchwork@sourceware.org>; Thu, 15 Sep 2022 20:17:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27EE5383A218 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663273027; bh=WizLCyef7zHDjuWJcaBlitTrmM3RF1M34LpCcPxkbrU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pDYunFlOAU4Cch2TWFe92evUgL00DpbJ9YqszjmoQ2cjUc/P6vJ2rmB1fyYL6Q5rC uQf0MTCN0Q95srm3mfW+BSEif5KFlJ1xO8cdmE8XnFSzHst6i7T5KeJ3AhvfCbf2Kh pVO45m+v7eGqYQqKeSLTf9a07HfnAvSYGOlrO8t4= 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 340B5384BC2C for <gcc-patches@gcc.gnu.org>; Thu, 15 Sep 2022 20:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 340B5384BC2C 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-614-JOb7ZCc2M7CsuSCsdZPcmA-1; Thu, 15 Sep 2022 16:16:36 -0400 X-MC-Unique: JOb7ZCc2M7CsuSCsdZPcmA-1 Received: by mail-qt1-f200.google.com with SMTP id g21-20020ac87d15000000b0035bb6f08778so10012719qtb.2 for <gcc-patches@gcc.gnu.org>; Thu, 15 Sep 2022 13:16:36 -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=WizLCyef7zHDjuWJcaBlitTrmM3RF1M34LpCcPxkbrU=; b=HkHcCLONyVjvGR1IExUPAT8iDcYFeeuaoDl7bzBRKN4E863vwyz6kL0sbKJQLqK1jg /YTftbFrmsHNTH3QCM6KHoW5CEwPihDo3i4IzSy5l4n9k3Rh07qT7NVnR1CGKagL5XNa lKFnGDmTysMulgfRLBT0FzVEoSKdEsLqL9X8HPiUtxviznU+ubPvzIpsK6qwLXw07Kfg Mxng+hSvB7aJlILcyW1LxZQHvprmRmIeTYCPJ6KUf0zkIGjQHR66GWzpt1mZUiYnoTIn SrKk/kpQD9EBEbq/w7wmZB1/8ZtqaWps5E0RvgSHIXVNV07sFXMp+GEsC436jvjjiG6d XAnw== X-Gm-Message-State: ACrzQf0YSX4moW0NndLhAQ0nMmWxZxfsgaISttTxkeFp0c9tvSUVgZNf mQRBay8GCT4zC6KluTfKcpxK2r2ShGvUs1kmJC0Y8Vwy+FBrLyM8VvY+9qQ3m5NfnBVx9i4ZwX+ 5v7WoCut2Wh9TN2KZZyExNvtrdRpRoMJgzCALYCTBy2THoq4XLHR7qDJ/B5jolTBkhDI= X-Received: by 2002:a05:622a:138b:b0:35b:b619:b87d with SMTP id o11-20020a05622a138b00b0035bb619b87dmr1617083qtk.146.1663272996166; Thu, 15 Sep 2022 13:16:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5w7IgMzanCwrtaW1kl6/+THf8Xzp9Fvz47ympeCgjzzwwUS+SuZzCl+2bZ3DVMFCpY8hMVwA== X-Received: by 2002:a05:622a:138b:b0:35b:b619:b87d with SMTP id o11-20020a05622a138b00b0035bb619b87dmr1617062qtk.146.1663272995922; Thu, 15 Sep 2022 13:16:35 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id a7-20020ac86107000000b0035ba3cae6basm4157138qtm.34.2022.09.15.13.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 13:16:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: modules ICE with typename friend declaration Date: Thu, 15 Sep 2022 16:16:27 -0400 Message-Id: <20220915201627.2942314-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.3.662.g36f8e7ed7d 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=-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 <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> Cc: nathan@acm.org 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++: modules ICE with typename friend declaration
|
|
Commit Message
Patrick Palka
Sept. 15, 2022, 8:16 p.m. UTC
A couple of xtreme-header-* modules tests began ICEing in C++23 mode ever since r13-2650-g5d84a4418aa962 introduced into <ranges> the dependently scoped friend declaration friend /* typename */ _OuterIter::value_type; ultimately because the streaming code assumes a TYPE_P friend must be a class type, but here it's a TYPENAME_TYPE, which doesn't have a TEMPLATE_INFO or CLASSTYPE_BEFRIENDING_CLASSES. This patch tries to correct this in a minimal way. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * module.cc (friend_from_decl_list): Don't consider CLASSTYPE_TEMPLATE_INFO for a TYPENAME_TYPE friend. (trees_in::read_class_def): Don't add to CLASSTYPE_BEFRIENDING_CLASSES for a TYPENAME_TYPE friend. gcc/testsuite/ChangeLog: * g++.dg/modules/typename-friend.C: New test. --- gcc/cp/module.cc | 5 +++-- gcc/testsuite/g++.dg/modules/typename-friend.C | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/typename-friend.C
Comments
Thanks, this looks right. Sigh templates can mess up ones mental invariants! The test case should really be a foo_[ab].C kind, to test both sides of the streaming. Bonus points for using the template after importing. And you need the dg-module-cmi annotation to check /and then delete/ the gcm file produced. nathan On Thu, Sep 15, 2022, 22:16 Patrick Palka <ppalka@redhat.com> wrote: > A couple of xtreme-header-* modules tests began ICEing in C++23 mode > ever since r13-2650-g5d84a4418aa962 introduced into <ranges> the > dependently scoped friend declaration > > friend /* typename */ _OuterIter::value_type; > > ultimately because the streaming code assumes a TYPE_P friend must > be a class type, but here it's a TYPENAME_TYPE, which doesn't have > a TEMPLATE_INFO or CLASSTYPE_BEFRIENDING_CLASSES. This patch tries > to correct this in a minimal way. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > gcc/cp/ChangeLog: > > * module.cc (friend_from_decl_list): Don't consider > CLASSTYPE_TEMPLATE_INFO for a TYPENAME_TYPE friend. > (trees_in::read_class_def): Don't add to > CLASSTYPE_BEFRIENDING_CLASSES for a TYPENAME_TYPE friend. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/typename-friend.C: New test. > --- > gcc/cp/module.cc | 5 +++-- > gcc/testsuite/g++.dg/modules/typename-friend.C | 9 +++++++++ > 2 files changed, 12 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/modules/typename-friend.C > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index f27f4d091e5..1a1ff5be574 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -4734,7 +4734,8 @@ friend_from_decl_list (tree frnd) > if (TYPE_P (frnd)) > { > res = TYPE_NAME (frnd); > - if (CLASSTYPE_TEMPLATE_INFO (frnd)) > + if (CLASS_TYPE_P (frnd) > + && CLASSTYPE_TEMPLATE_INFO (frnd)) > tmpl = CLASSTYPE_TI_TEMPLATE (frnd); > } > else if (DECL_TEMPLATE_INFO (frnd)) > @@ -12121,7 +12122,7 @@ trees_in::read_class_def (tree defn, tree > maybe_template) > { > tree f = TREE_VALUE (friend_classes); > > - if (TYPE_P (f)) > + if (CLASS_TYPE_P (f)) > { > CLASSTYPE_BEFRIENDING_CLASSES (f) > = tree_cons (NULL_TREE, type, > diff --git a/gcc/testsuite/g++.dg/modules/typename-friend.C > b/gcc/testsuite/g++.dg/modules/typename-friend.C > new file mode 100644 > index 00000000000..d8faf7955c3 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/typename-friend.C > @@ -0,0 +1,9 @@ > +// { dg-additional-options "-fmodules-ts" } > + > +export module x; > + > +template<class T> > +struct A { > + friend typename T::type; > + friend void f(A) { } > +}; > -- > 2.37.3.662.g36f8e7ed7d > >
On Fri, 16 Sep 2022, Nathan Sidwell wrote: > Thanks, this looks right. Sigh templates can mess up ones mental invariants! > The test case should really be a foo_[ab].C kind, to test both sides of the streaming. Bonus points for using the template after importing. And you need the dg-module-cmi annotation to check /and then > delete/ the gcm file produced. Aha, thanks very much for the pointers, I redid the testcase using lang-3_[abc].C as an example. How does the following look? -- >8 -- gcc/cp/ChangeLog: * module.cc (friend_from_decl_list): Don't consider CLASSTYPE_TEMPLATE_INFO for a TYPENAME_TYPE friend. (trees_in::read_class_def): Don't add to CLASSTYPE_BEFRIENDING_CLASSES for a TYPENAME_TYPE friend. gcc/testsuite/ChangeLog: * g++.dg/modules/typename-friend_a.C: New test. * g++.dg/modules/typename-friend_b.C: New test. --- gcc/cp/module.cc | 5 +++-- gcc/testsuite/g++.dg/modules/typename-friend_a.C | 11 +++++++++++ gcc/testsuite/g++.dg/modules/typename-friend_b.C | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/typename-friend_a.C create mode 100644 gcc/testsuite/g++.dg/modules/typename-friend_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f27f4d091e5..1a1ff5be574 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -4734,7 +4734,8 @@ friend_from_decl_list (tree frnd) if (TYPE_P (frnd)) { res = TYPE_NAME (frnd); - if (CLASSTYPE_TEMPLATE_INFO (frnd)) + if (CLASS_TYPE_P (frnd) + && CLASSTYPE_TEMPLATE_INFO (frnd)) tmpl = CLASSTYPE_TI_TEMPLATE (frnd); } else if (DECL_TEMPLATE_INFO (frnd)) @@ -12121,7 +12122,7 @@ trees_in::read_class_def (tree defn, tree maybe_template) { tree f = TREE_VALUE (friend_classes); - if (TYPE_P (f)) + if (CLASS_TYPE_P (f)) { CLASSTYPE_BEFRIENDING_CLASSES (f) = tree_cons (NULL_TREE, type, diff --git a/gcc/testsuite/g++.dg/modules/typename-friend_a.C b/gcc/testsuite/g++.dg/modules/typename-friend_a.C new file mode 100644 index 00000000000..aa426fe6cf0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/typename-friend_a.C @@ -0,0 +1,11 @@ +// { dg-additional-options "-fmodules-ts" } +export module foo; +// { dg-module-cmi foo } + +template<class T> +struct A { + friend typename T::type; + friend void f(A) { } +private: + static constexpr int value = 42; +}; diff --git a/gcc/testsuite/g++.dg/modules/typename-friend_b.C b/gcc/testsuite/g++.dg/modules/typename-friend_b.C new file mode 100644 index 00000000000..97da9d82e11 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/typename-friend_b.C @@ -0,0 +1,6 @@ +// { dg-additional-options "-fmodules-ts" } +module foo; + +struct C; +struct B { using type = C; }; +struct C { static_assert(A<B>::value == 42); };
On 16 September 2022 17:54:32 CEST, Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >+++ b/gcc/testsuite/g++.dg/modules/typename-friend_a.C >@@ -0,0 +1,11 @@ >+// { dg-additional-options "-fmodules-ts" } >+export module foo; >+// { dg-module-cmi foo } >+ If that's a constant, repeating pain, you could instrument the test suite so that upon seeing -fmodules-ts (or maybe a later std) it greps for export module and calls dg-module-cmi on those names automatically on its own. We do the same for stuff like PCH or fortran module .mod or many other cleanup stuff because such manual annotations are IMHO a waste of developer resources.. Just a thought.. cheers,
On 9/16/22 11:54, Patrick Palka wrote: > On Fri, 16 Sep 2022, Nathan Sidwell wrote: > >> Thanks, this looks right. Sigh templates can mess up ones mental invariants! >> The test case should really be a foo_[ab].C kind, to test both sides of the streaming. Bonus points for using the template after importing. And you need the dg-module-cmi annotation to check /and then >> delete/ the gcm file produced. > > Aha, thanks very much for the pointers, I redid the testcase using > lang-3_[abc].C as an example. How does the following look? > yes, that's right, thanks! nathan
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f27f4d091e5..1a1ff5be574 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -4734,7 +4734,8 @@ friend_from_decl_list (tree frnd) if (TYPE_P (frnd)) { res = TYPE_NAME (frnd); - if (CLASSTYPE_TEMPLATE_INFO (frnd)) + if (CLASS_TYPE_P (frnd) + && CLASSTYPE_TEMPLATE_INFO (frnd)) tmpl = CLASSTYPE_TI_TEMPLATE (frnd); } else if (DECL_TEMPLATE_INFO (frnd)) @@ -12121,7 +12122,7 @@ trees_in::read_class_def (tree defn, tree maybe_template) { tree f = TREE_VALUE (friend_classes); - if (TYPE_P (f)) + if (CLASS_TYPE_P (f)) { CLASSTYPE_BEFRIENDING_CLASSES (f) = tree_cons (NULL_TREE, type, diff --git a/gcc/testsuite/g++.dg/modules/typename-friend.C b/gcc/testsuite/g++.dg/modules/typename-friend.C new file mode 100644 index 00000000000..d8faf7955c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/typename-friend.C @@ -0,0 +1,9 @@ +// { dg-additional-options "-fmodules-ts" } + +export module x; + +template<class T> +struct A { + friend typename T::type; + friend void f(A) { } +};