From patchwork Thu Sep 22 18:25:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp330555wrt; Thu, 22 Sep 2022 11:25:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KdhP8YZkHH6sbZgrEfuLXgNpQCUxl4QSH3pKT95cliq/2XlSSl8UWGGPptduwP8V75Nry X-Received: by 2002:a17:906:8457:b0:779:9f0a:fb with SMTP id e23-20020a170906845700b007799f0a00fbmr4061692ejy.665.1663871153897; Thu, 22 Sep 2022 11:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663871153; cv=none; d=google.com; s=arc-20160816; b=tJSAwcZUpOjW0698DK4srahtLVTfr0hhvkGX38xxDP09PK8/R+YbfuwpskZnBcFBWg DFHyvl+JAyAPkJbhc0Ik/KFkBzy+gMQNBhbz8REKpsjErAWczInIegtIhNimeR5fuaq6 BQNKjtXm8p4tyiqKXf8ZwpvG+vAMAzjeqXl3Nkj6iUv090AwNCLgHG5zwsooy+/SzZ2Y 0mbIPtAr7MViWc5zDn0kbDorgdwxWJzLqN9O72clv7BBMNcJshd7whNDkVRZ61xNxIau AfeiMcqUEEGT3hbEMySJIpFbzv8OPKVKNsdWnUvZ5b2kiT16n0F5eomSmvNOwbX4xEXW kzQQ== 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=/V+0gpvqUL0OGe7em1WpuvEfsXa75LZl5ogUQabWy3E=; b=Pk6E01ApIhH1fZzeX5rYWt/zR0qVf56CSHTGvfu+l8CBYxJMymjn8w5S7pULVRidZz dyJXfwwdznyyhCQaBkItJR5VwLJ4Jlho6Kq4At+dPrrGNgENq6O0wy2u6f8oznVIumjE i9g713PiEtzWl+N61rRHRj9GTFNG0AxFaN+Xwi0dbbcFWFpnBYBARwnkJDafbAJqXH9r Cd9MCWxaiwYCNFjCU56ynGBTEakpJyJRgECRFhu7UmvUS+Wzq/C22/xhNITsxUq72djB tDma2ZVYXERqeBCm/EzotBAQEbWio1B0OWzqB7uT18OnaCk4Z2YSAeQCYmATgsQvRLhG aLlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="N8P1B3h/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bs15-20020a170906d1cf00b0073f2c8b20a6si4803241ejb.852.2022.09.22.11.25.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 11:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="N8P1B3h/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 94A1D3858017 for ; Thu, 22 Sep 2022 18:25:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94A1D3858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663871152; bh=/V+0gpvqUL0OGe7em1WpuvEfsXa75LZl5ogUQabWy3E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=N8P1B3h/T/HlArrdsMrrTbj8L6E2IsOMM38U4YZ9Xbyr0B2jkOyOsDQvM+YSI6ZLA Ckl7XZ0ycGnTkVzWTXIBPbpd/SE84ITzC0ImHEO56hN9/sCpptpwdW/mBDX8fIqfbS gMSOkz2K34AIbrSMN8BKzeNXU2S7fqNv6GyPIZKo= 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 181383858D38 for ; Thu, 22 Sep 2022 18:25:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 181383858D38 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-621-PwceFq-FPVS4XTvalrsAMg-1; Thu, 22 Sep 2022 14:25:07 -0400 X-MC-Unique: PwceFq-FPVS4XTvalrsAMg-1 Received: by mail-qk1-f199.google.com with SMTP id bi3-20020a05620a318300b006cf2d389cdaso7171311qkb.8 for ; Thu, 22 Sep 2022 11:25:07 -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=/V+0gpvqUL0OGe7em1WpuvEfsXa75LZl5ogUQabWy3E=; b=5mmihFWqnXYfjIKczRliXQ7Q3o/WJ24iGt1L0D0MIdUvHd2EcG8g4/mM89SHvVqJv5 zLvpKlYcuKaLf/dM32ocGvunS0IyirOwRpNQDvHyb4lwoWdxDdgKcGSoCmczCsmPoECL dyY6KL1CTkgMH5PjNAA62araLgSH4QgFe51BZntRGGP7KB37PinCsdXRDPtyKee8igzZ DY1D7NloSbZ3GHI4Y6+rfoixeol08mIA+HoyRW9sUi1093opQvCyKFv8eA49nqES9IsF IPFg96DTfpF4IRXeyxgLrtMVh2hb4ZnsW5vP2XhU+TzuYSfWXpnfg1Ggw+tmhJCql3wK ZLWA== X-Gm-Message-State: ACrzQf2ikN4+rm1U9tzUSo/uNZMErrbVPsBIokrHZN0g/ulkkGC08RAG QmMXUE8JjILhNSWv2pr7VADEWZjoHc3lB//wKtAKBUljwVCMId6TG3tMuM6rVVW1jbdwaML42K+ pnbzQk22XGKcjsKrpIEzDfsurEtwJXXkDVZmyjRCgVY8f0O2XObtilYrvtZTMRrJnl5k= X-Received: by 2002:a0c:f4cc:0:b0:4aa:a471:978f with SMTP id o12-20020a0cf4cc000000b004aaa471978fmr3806216qvm.80.1663871105503; Thu, 22 Sep 2022 11:25:05 -0700 (PDT) X-Received: by 2002:a0c:f4cc:0:b0:4aa:a471:978f with SMTP id o12-20020a0cf4cc000000b004aaa471978fmr3806194qvm.80.1663871105221; Thu, 22 Sep 2022 11:25:05 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id l5-20020a05620a28c500b006bc1512986esm4648851qkp.97.2022.09.22.11.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 11:25:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: ICE with class NTTP argument [PR100616] Date: Thu, 22 Sep 2022 14:25:02 -0400 Message-Id: <20220922182502.3218391-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc0.52.gdda7228a83 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?1744695359192254314?= X-GMAIL-MSGID: =?utf-8?q?1744695359192254314?= When streaming in the artificial VAR_DECL synthesized for a class NTTP argument, we end up crashing from complete_vars because the call to maybe_register_incomplete_var from add_module_namespace_decl for this VAR_DECL pushes an unexpected NULL_TREE type onto the incomplete_vars vector. This patch fixes this by checking for NULL_TREE before pushing onto the vector. This avoids the crash, but I noticed we still appear to mishandle these artificial VAR_DECLs across translation units: the lookup from get_template_parm_object for an existing VAR_DECL for the given class NTTP argument fails to find the streamed-in VAR_DECL from the other translation unit, so we end up creating a second VAR_DECL, but that causes specialization equivalency issues in the XFAIL'd part of the below test. I'm afraid I don't understand why the lookup fails here despite having done add_module_namespace_decl during stream-in, but fixing the ICE seems like a safe and useful step towards enabling class NTTP arguments used in modules. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/100616 gcc/cp/ChangeLog: * decl.cc (maybe_register_incomplete_var): Check result of outermost_open_class. gcc/testsuite/ChangeLog: * g++.dg/modules/pr100616_a.C: New test. * g++.dg/modules/pr100616_b.C: New test. --- gcc/cp/decl.cc | 8 +++++--- gcc/testsuite/g++.dg/modules/pr100616_a.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr100616_b.C | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr100616_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr100616_b.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 80467c19254..722b64793ed 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -18235,9 +18235,11 @@ maybe_register_incomplete_var (tree var) { /* When the outermost open class is complete we can resolve any pointers-to-members. */ - tree context = outermost_open_class (); - incomplete_var iv = {var, context}; - vec_safe_push (incomplete_vars, iv); + if (tree context = outermost_open_class ()) + { + incomplete_var iv = {var, context}; + vec_safe_push (incomplete_vars, iv); + } } } } diff --git a/gcc/testsuite/g++.dg/modules/pr100616_a.C b/gcc/testsuite/g++.dg/modules/pr100616_a.C new file mode 100644 index 00000000000..788af2eb533 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr100616_a.C @@ -0,0 +1,8 @@ +// PR c++/100616 +// { dg-additional-options "-std=c++20 -fmodules-ts" } +// { dg-module-cmi pr100616 } +export module pr100616; + +template struct C { }; +struct A { }; +C c1; diff --git a/gcc/testsuite/g++.dg/modules/pr100616_b.C b/gcc/testsuite/g++.dg/modules/pr100616_b.C new file mode 100644 index 00000000000..8037ceda3ed --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr100616_b.C @@ -0,0 +1,10 @@ +// PR c++/100616 +// { dg-additional-options "-std=c++20 -fmodules-ts" } +module pr100616; + +C c2; + +// FIXME: We don't reuse the artificial VAR_DECL for the class NTTP argument A{} +// from the other translation unit, which causes these types to be different. +using ty_a = decltype(c1); +using ty_a = decltype(c2); // { dg-bogus "conflicting" "" { xfail *-*-* } }