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: 2757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp284993wrs; Fri, 14 Oct 2022 10:02:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52KfqRdM8xHSWVVrxP+3fiPLO8KQdzcVYxmUaLWG0oLrfCYue8imRjVMfwLR5UqxgPvKOE X-Received: by 2002:a50:9991:0:b0:458:a612:bf5a with SMTP id m17-20020a509991000000b00458a612bf5amr5087754edb.22.1665766929961; Fri, 14 Oct 2022 10:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665766929; cv=none; d=google.com; s=arc-20160816; b=BHltKIgwb35SCsVFRVSejKDeP7tHkzQ6cpMw399vJoCrKjCxZ0lA+gMyULhIo8mM7B wF9tXv2Fd7xYmFYHu15Fhn3srR0SKtxLaC0Tw9v3+I5tKfyI4uVvpYY4k/T18Xj74E/d yEpuGEBIHB/2utoAP7Q1fXrhFp+9BDvlnMcj3P2YrohJo3ZovnIUU1kciWjvnUJbmzYQ q0qrkJJCDbHedLJueGzrIe0itU30JhlLlUI5c7cWtFHiJEqHdkfbyOG1FgUvO2rN1V+3 zm9nwsxbmoQIEbel6KEiW9avXhCX9Ex/f+276Z6DIJKgp1ikUGmEqjfvwuVG/sp9UFUa 8uPA== 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=37RBCZVdGboZcqra+MnSPIeM1HBXQcN/HUuiUGcA1n8=; b=tnmzD9ZoWxtQpMIkxGXFczQimkc05rgycdMMTZCphKek5OY0JXaa7UINp5cCdDO2O3 56ZsEoJdyFFMVyrimctvag5I4o7Iikhx4TgcSKQ4kwW7DQYXaZaz2mlo/WWKag3jxzdA HTyfE7rgrIcMVBsiQ5DvuUuxGJ4n3i2dyfQ0w1SKAbByyvJ79mOLAHZsQtcPWCVIW/GC eGi0or0RGpHKjGrR5DC8Shs0MDTtcrgHX59XW3JQMdYj6Xa5+PMC9TALy3KU/DSzSQ+0 NrenuCOSOp+mptlid8GoZGKg7eeoKCivbs3OBYu+ctrX4PlpWn7I8zp4uEDHcWzGaNrn 9JKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZpoFRsDO; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y3-20020aa7c243000000b00457263f9ee0si2258632edo.93.2022.10.14.10.02.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 10:02:09 -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=ZpoFRsDO; 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 0C28A385800B for ; Fri, 14 Oct 2022 17:02:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C28A385800B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665766929; 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=ZpoFRsDO+9Fgpp+S7M9b1Ozcwl9eG4yif/uzp+O18yUG7K/HQ2f8doEx5mukfp+aJ SpKjs0Nah7UhzrwSIqOps8E+B1LzJzRuyFoWUVAmwrc3EosHaI+u8r0OFyTf0QJrbd O79x7zjaxnBHXKIGrMd9jGFcxwf+fchumnofaQEk= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746683224588542147?= X-GMAIL-MSGID: =?utf-8?q?1746683224588542147?= 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()));