From patchwork Mon Feb 26 20:52:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 86404 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 A0DD53858287 for ; Mon, 26 Feb 2024 20:53:04 +0000 (GMT) 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 6D0733858409 for ; Mon, 26 Feb 2024 20:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D0733858409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6D0733858409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708980758; cv=none; b=SlDL3jVfKs+NIWJWr1PCGP17K+UcrmB5z+LM4s2BT+3xHu3BDg8J3ls9jwCauC5nGPDTr5c8c57Kqv9V166uRw9yg2QKwTENG1mslMQplwtAZkSuMtEwommfgaICQU6L57RMoWnjFBP8OMBurjAelfp4ueJKA2RW+FhaRT/qUFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708980758; c=relaxed/simple; bh=PHpkx/zTzrolE8sZOiFaZWmMIr501wU4jjSSVhbSygo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q8+nO6Y5ce4hrMhZqml+AtGQGEqK11G1uwzPjHW98MlXUncmm2chvwtWvilHb+lZBI2SgWl1QBH2WcoXWDfK63t2Y/gyeDRypFbkAdUimZaNlH4RoEx4c3gD3s/jQLcKNDMFtgBIJ+WI25A6hJxHtmUuBYCB5rR3zcF8UggXmgQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708980757; 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=/dnhPMbpWLF4cSoGgfcPAk2LUX9k9kNviu6G+CSU2Zs=; b=jAFbWl5I1C9CZQRYS4tldG6R7kXxTJzuRCBC/bxfQgbGvB55nU1mLRuuOIZ1l7mpJm8wn6 w1JQxaRVmnzaqihkSYm5hHRTbWqc24QAeZV6by45oHc3iUp8AyNOZal4MfWd52niDurQ44 vFwJZLP9nkxJ4hU+Fz6JKBP2ZCqrObI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-Sj1RNjciPzOxyJ2TM-wEuA-1; Mon, 26 Feb 2024 15:52:35 -0500 X-MC-Unique: Sj1RNjciPzOxyJ2TM-wEuA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-787988f273dso376897085a.3 for ; Mon, 26 Feb 2024 12:52:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708980753; x=1709585553; 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=/dnhPMbpWLF4cSoGgfcPAk2LUX9k9kNviu6G+CSU2Zs=; b=MlyaMpBus/OJxl4JZYi5if9BcIdeIlJFYBHxMH+9sM1ogJgYoY58jmWXiFR1U50RMl he1B8WJqvll290hZR9Np4DVaSQZyD8q/6kst/dgJGaOA2jJSk45EDTONxYjWQvs4ubK6 jHyivJ9R3WefyQi05r6LPsL6xG4etrW4PcjjVbXjIIWcyN2thCeYZCoKaVosZCJfd6ko u/hz+zI1jjp+YG5rH0qSSaLZJN3BtprSsIcTWlz9CT9eWGfdZvz2RgWhZTxpy4kcMLoB 7fvnXKjjeCjWmLjFKLZfH2FupOCmzf7csCOdx+P36Mv4TNg5j5ZMfINc8jWrtA28EBSI IQkA== X-Gm-Message-State: AOJu0Yza/+d7A8wseKsEzpbntGesQT6/tUDbDFIwTE/10WdFvrgOB/jC FiDw0Gq2cVFOabejtjEGxTBFE2aa/XVa+dzHoZyK9gr1j4Lex4WcVDaScSB3Quu7wnzZybpv7lw dXwb/llfbAzxXUoIwnZ/9S6U8ZwgItTRvLQ0b3pXOBeTrBL0357u9fGsMzyhUwzX4l4JE3W7pp+ D23bi5bE5DJ51eDVfOzHZAn8qoHf9XiwpZh3dD X-Received: by 2002:a05:620a:1222:b0:787:dee1:9ee8 with SMTP id v2-20020a05620a122200b00787dee19ee8mr247292qkj.56.1708980753490; Mon, 26 Feb 2024 12:52:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFodwrkzx3p4X3/3v+sxG+vvccg4EusFcBWcX4mtgvtkUYs/tbkxOXsQf5tyYr035FLrWLTbg== X-Received: by 2002:a05:620a:1222:b0:787:dee1:9ee8 with SMTP id v2-20020a05620a122200b00787dee19ee8mr247274qkj.56.1708980753049; Mon, 26 Feb 2024 12:52:33 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id j22-20020a05620a147600b007876a732823sm2861800qkl.25.2024.02.26.12.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 12:52:32 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka Subject: [PATCH] c++/modules: complete_vars ICE with non-exported constexpr var Date: Mon, 26 Feb 2024 15:52:30 -0500 Message-ID: <20240226205230.2403133-1-ppalka@redhat.com> X-Mailer: git-send-email 2.44.0.rc1.15.g4fc51f00ef MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here during stream-in of the non-exported constexpr var 'a' we call maybe_register_incomplete_var, which ends up taking the second branch and pushing {a, NULL_TREE} onto incomplete_vars. We later ICE from complete_vars due to this NULL_TREE class context. Judging by the two commits that introduced/modified this part of maybe_register_incomplete_var, r196852 and r214333, ISTM this branch is really only concerned with constexpr static data members (whose initializer may contain a pointer-to-member for a currently open class). So this patch restricts this branch accordingly so it's not inadvertently taken during stream-in. gcc/cp/ChangeLog: * decl.cc (maybe_register_incomplete_var): Restrict second branch to static data members from a currently open class. gcc/testsuite/ChangeLog: * g++.dg/modules/cexpr-4_a.C: New test. * g++.dg/modules/cexpr-4_b.C: New test. --- gcc/cp/decl.cc | 2 ++ gcc/testsuite/g++.dg/modules/cexpr-4_a.C | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/cexpr-4_b.C | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/cexpr-4_a.C create mode 100644 gcc/testsuite/g++.dg/modules/cexpr-4_b.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e47f694e4e5..82b5bc83927 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -18976,6 +18976,8 @@ maybe_register_incomplete_var (tree var) vec_safe_push (incomplete_vars, iv); } else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var)) + && DECL_CLASS_SCOPE_P (var) + && currently_open_class (DECL_CONTEXT (var)) && decl_constant_var_p (var) && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type))) { diff --git a/gcc/testsuite/g++.dg/modules/cexpr-4_a.C b/gcc/testsuite/g++.dg/modules/cexpr-4_a.C new file mode 100644 index 00000000000..cec2e351898 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/cexpr-4_a.C @@ -0,0 +1,12 @@ +// { dg-additional-options "-fmodules-ts" } +export module Cexpr4; +// { dg-module-cmi "Cexpr4" } + +struct A { int v = 42; }; + +constexpr A a; + +export +inline int f() { + return a.v; +} diff --git a/gcc/testsuite/g++.dg/modules/cexpr-4_b.C b/gcc/testsuite/g++.dg/modules/cexpr-4_b.C new file mode 100644 index 00000000000..6fbe652bf22 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/cexpr-4_b.C @@ -0,0 +1,6 @@ +// { dg-additional-options "-fmodules-ts" } +import Cexpr4; + +int w = f(); + +struct A { };