From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663871108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/V+0gpvqUL0OGe7em1WpuvEfsXa75LZl5ogUQabWy3E=; b=Tt8LtSCLxWQp87i2m1xfvYi3IkYbJOjGNOKgBTmfNgCpgqp2dtN+6aTLiWDZ/rPy17RnFI I/lMXYD+sFs9j04QZGuDkVQdH9vIt2m1gDQhd4SNFtP1V8oDkwKwv4g6UlbMkfzPWImKfO LQ58FmGscOkw8bn1vb46D/N20uycnKo= 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-Google-Smtp-Source: AMsMyM7VTBimFwTFU7uyV/esJ5IKeShEVWq3TOjvDY2Ogclg0qwPpiEKN5iIIhSvX4qDCy8EgEhW2Q== 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka 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 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 List-Id: 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 *-*-* } } -- 2.38.0.rc0.52.gdda7228a83