From patchwork Fri Oct 14 17:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 58851 Return-Path: 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 97F4738582B7 for ; Fri, 14 Oct 2022 17:01:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97F4738582B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665766914; bh=37RBCZVdGboZcqra+MnSPIeM1HBXQcN/HUuiUGcA1n8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uRaRez6nVTEwi5J7AGfh5n33giGeG9Z5GR/Q28echVXV+3kHrv4SCh8c05slxqaXh tSXoNwz4eBbSV2+mmrHk5I85muWk1gCNxbdgwfufdwyTMK+bLj7MFGhDpdFkvpt0vt b/z6c3tcImxLr8CP4x4FdpoDAlyMlyzG0h4MvuSo= 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 DEEE43858C83 for ; Fri, 14 Oct 2022 17:00:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEEE43858C83 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-43-bEimETnKMkOYCddvLrMFSQ-1; Fri, 14 Oct 2022 13:00:43 -0400 X-MC-Unique: bEimETnKMkOYCddvLrMFSQ-1 Received: by mail-qv1-f72.google.com with SMTP id dh7-20020ad458c7000000b004b1c8f7205eso3800760qvb.5 for ; Fri, 14 Oct 2022 10:00:43 -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:message-id :reply-to; bh=37RBCZVdGboZcqra+MnSPIeM1HBXQcN/HUuiUGcA1n8=; b=H6O3m2nDlfgg7ihZyEzPSbEh86j9XVXsf7oTRvH5hNZD/ReIme3oAzC0PudNI6+nbv 4iY3otAHBxUOd53jof+6fpXLllBwHbhmB4Qbs/oPDfl5WTpaAPa4wZZrSS4Ma94qmbdR grsbEcOyDwJ4/Icewq2SpQswsPrCuLdSBNtnYXOf4rWiAbi65YAfL2TDA4oSsh8N9rQg asgp8aG3VSHDCj81bjgVTyztp/nL33KH7y6B+/4guv9gR5/uD+NdpzoNhrTz6tFdUhZk 2+8y39GFkh+/SNX66E33Vj8pURSgHu/Kp2SwaaU5l5bQORYlC/K8EHXnaYXW11fgXDXd MfzA== X-Gm-Message-State: ACrzQf2ZhGlAMP1+6NrYgWOAuJQEVbO4nPYlyH4etNraqA3ud4O9P8aN 2gbm2EUmvizV7DAKHaKZXwWL7jzQKz5rUY9wFUFQeDr6DtVgSJ9rzXFAnsLAtTeWclkfLEWOUSl bZRwcJU/dGlhWHyzOXlc7bNv1EBdHH5BCn0hhjuHpGN/ZtwkJXw9N9BKQ1VJvRpeOpCw= X-Received: by 2002:a05:622a:449:b0:39c:d73a:e7d5 with SMTP id o9-20020a05622a044900b0039cd73ae7d5mr3861237qtx.276.1665766832234; Fri, 14 Oct 2022 10:00:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HP0ok74gcgKSoI5b0ASc7u3AKOVVnFQtkBNWXiD4wEdoYuR7JvQSeczM9st9SzJ76eCP2jg== X-Received: by 2002:a05:622a:449:b0:39c:d73a:e7d5 with SMTP id o9-20020a05622a044900b0039cd73ae7d5mr3861202qtx.276.1665766831878; Fri, 14 Oct 2022 10:00:31 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u3-20020a05620a454300b006eed094dcdasm1228600qkp.70.2022.10.14.10.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 10:00:31 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: streaming constexpr_fundef [PR101449] Date: Fri, 14 Oct 2022 13:00:18 -0400 Message-Id: <20221014170018.892575-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.0 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, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" IIUC we currently avoid streaming the RESULT_DECL and PARM_DECLs of a constexpr_fundef entry under the assumption that they're just copies of the DECL_RESULT and DECL_ARGUMENTS of the FUNCTION_DECL. Thus we can just make new copies of DECL_RESULT and DECL_ARGUMENTs on stream in rather than separately streaming them. Unfortunately this assumption isn't true generally: the FUNCTION_DECL contains genericized trees, whereas the constexpr_fundef entry contains pre-GENERIC trees. So in particular DECL_RESULT and DECL_ARGUMENTs may have been turned into invisiref parms which we don't handle during during constexpr evaluation and so we ICE in the below testcase. This patch fixes this by faithfully streaming the RESULT_DECL and PARM_DECLs of a constexpr_fundef entry. PR c++/101449 gcc/cp/ChangeLog: * module.cc (trees_out::write_function_def): Stream the parms and result of the constexpr_fundef entry. (trees_in::read_function_def): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/cexpr-3_a.C: New test. * g++.dg/modules/cexpr-3_b.C: New test. --- gcc/cp/module.cc | 59 ++++-------------------- gcc/testsuite/g++.dg/modules/cexpr-3_a.C | 14 ++++++ gcc/testsuite/g++.dg/modules/cexpr-3_b.C | 7 +++ 3 files changed, 29 insertions(+), 51 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/cexpr-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/cexpr-3_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 7ffeefa7c1f..999ff3faafc 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11553,34 +11553,13 @@ trees_out::write_function_def (tree decl) tree_node (DECL_FRIEND_CONTEXT (decl)); constexpr_fundef *cexpr = retrieve_constexpr_fundef (decl); - int tag = 0; - if (cexpr) - { - if (cexpr->result == error_mark_node) - /* We'll stream the RESULT_DECL naturally during the - serialization. We never need to fish it back again, so - that's ok. */ - tag = 0; - else - tag = insert (cexpr->result); - } + if (streaming_p ()) + u (cexpr != nullptr); + if (cexpr) { - i (tag); - if (tag) - dump (dumper::TREE) - && dump ("Constexpr:%d result %N", tag, cexpr->result); - } - if (tag) - { - unsigned ix = 0; - for (tree parm = cexpr->parms; parm; parm = DECL_CHAIN (parm), ix++) - { - tag = insert (parm); - if (streaming_p ()) - dump (dumper::TREE) - && dump ("Constexpr:%d parm:%u %N", tag, ix, parm); - } + chained_decls (cexpr->parms); + tree_node (cexpr->result); tree_node (cexpr->body); } @@ -11613,32 +11592,10 @@ trees_in::read_function_def (tree decl, tree maybe_template) tree maybe_dup = odr_duplicate (maybe_template, DECL_SAVED_TREE (decl)); bool installing = maybe_dup && !DECL_SAVED_TREE (decl); - if (int wtag = i ()) + if (u ()) { - int tag = 1; - cexpr.result = error_mark_node; - - cexpr.result = copy_decl (result); - tag = insert (cexpr.result); - - if (wtag != tag) - set_overrun (); - dump (dumper::TREE) - && dump ("Constexpr:%d result %N", tag, cexpr.result); - - cexpr.parms = NULL_TREE; - tree *chain = &cexpr.parms; - unsigned ix = 0; - for (tree parm = DECL_ARGUMENTS (maybe_dup ? maybe_dup : decl); - parm; parm = DECL_CHAIN (parm), ix++) - { - tree p = copy_decl (parm); - tag = insert (p); - dump (dumper::TREE) - && dump ("Constexpr:%d parm:%u %N", tag, ix, p); - *chain = p; - chain = &DECL_CHAIN (p); - } + cexpr.parms = chained_decls (); + cexpr.result = tree_node (); cexpr.body = tree_node (); cexpr.decl = decl; } diff --git a/gcc/testsuite/g++.dg/modules/cexpr-3_a.C b/gcc/testsuite/g++.dg/modules/cexpr-3_a.C new file mode 100644 index 00000000000..be24bb43a7b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/cexpr-3_a.C @@ -0,0 +1,14 @@ +// PR c++/101449 +// { dg-additional-options -fmodules-ts } +// { dg-module-cmi pr101449 } + +export module pr101449; + +struct X { + bool b = true; + constexpr X() { } + constexpr X(const X&) { } +}; + +export constexpr X f() { return {}; } +export constexpr bool g(X x) { return x.b; } diff --git a/gcc/testsuite/g++.dg/modules/cexpr-3_b.C b/gcc/testsuite/g++.dg/modules/cexpr-3_b.C new file mode 100644 index 00000000000..cbf3be4fcab --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/cexpr-3_b.C @@ -0,0 +1,7 @@ +// PR c++/101449 +// { dg-additional-options -fmodules-ts } + +import pr101449; + +static_assert(f().b); +static_assert(g(f()));