From patchwork Wed Jan 3 12:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 184733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4993810dyb; Wed, 3 Jan 2024 04:43:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgtPeADic7HLm4E+IhtoYJG0tJv5NmRcq1wcAMBhaJ0ik/MNlf8tW+N8e0k8vVDkVBQv0Z X-Received: by 2002:ae9:f707:0:b0:781:d575:cb4f with SMTP id s7-20020ae9f707000000b00781d575cb4fmr3199744qkg.49.1704285816672; Wed, 03 Jan 2024 04:43:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704285816; cv=pass; d=google.com; s=arc-20160816; b=fMY+CA44vcpZJtl19fnodzxJr6utGxzLsiqcDzFrr/KvW64t3f+GRnli1ItVdg3VLc e6hQBVJzC/6DoaMiClY4lecb2NYnqZCRwIALt0SPJhgDxR+18tuhRc4iR2GOiNiwnip5 WMRbx1C1Yk/jK8vfU9BbRcEvwqGfxwFvncezrEObU31cWQ4K+we+NaYDhN74KjQ7mEpf sjb3SV3F/XaJ4qyqTNJp0Oq2Wv+D/2ioQLRbrSRvybH7u2EPc0sFcYrN29MY04fleIc0 TXPhyK+w2NOvqsNou+a2wq5gmrW0rCYdhbuJ82Wi0HOgWJbfya/hCJZHtecbvVppkgTw izGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:content-disposition :mime-version:references:subject:cc:to:from:date:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=/BpwCSw42VDWV3EnHxqnJhuCWMtfdO0C+sQH543fjn0=; fh=qzO3wbthSnmyfzK9xuMl/p4JuHJ0vwryuUQopRA3shc=; b=IK9iA/OfbNmEy37x0nyK0Jp948QF/UIvN5d3f6rvsq4Zj4wq4D4oh74D+FfjcT+DNK cAfiZEmiYc6lHI9iqHqPIYo+gtRtfWx1hb8NIjHjUvHyB8h5BqRTJXoac90Y1VjYlnol cluhrzV0zIda9df5xn9Qsquq0nXpOGbGWsb0xMrm0pkkzjHaSyEaTTug5LaLR+jJcOvi 7DP0EGlBuR6YnruBsDmC8/pR4EHRBajCRn3XzAMzuheXKN/R1yvUXvlacLeYb9K3mpWV OgEhef0pmZXLLzXjV+5gYKEPH+YBzpPDO1fRynsE198cMYG6E5znxAyp2qE7URIw6WDO +DSQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F3RKE5EG; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bq30-20020a05620a469e00b007815dcb5b66si17160800qkb.762.2024.01.03.04.43.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:43:36 -0800 (PST) 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=@gmail.com header.s=20230601 header.b=F3RKE5EG; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E48E3858291 for ; Wed, 3 Jan 2024 12:43:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 0C34E385842F for ; Wed, 3 Jan 2024 12:42:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C34E385842F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0C34E385842F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704285774; cv=none; b=VLGM/nIlqooWgyDYsiy3ITEr0IcI6WWtNv8Byjod9dysQKFwwoEPqfX2TiX1Xi0NrQ1Vz/dLEDy0UoXvIeHH7OkBCmHpP2rNvQoy1l0kvkaeKnqfZRmnd3FeLnl6nzTOQczKnckHxux3JZKCdroo7mhqUNzxMJaRlNZANDV+pFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704285774; c=relaxed/simple; bh=WNuTsP1ZP/s80cDk57E1IKWpKVqHo/svqTZxMlx64W4=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=wVz8hOElsgqooxBBNByLNnNpUVAwayI0e1vM/1+1KGD7JThHefpSdhfP+Y9Rp67TUv/qYu53/1SiguefKaX5FM5iIiPFscs+dy91nnTfiNzQlwkbf+0/kSvj1fetovQrYbThGpIJSUrc0yi9prr13JTUEBXiMn/znhhgRZ9pcTw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-28bd85bda06so4658760a91.3 for ; Wed, 03 Jan 2024 04:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704285770; x=1704890570; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=/BpwCSw42VDWV3EnHxqnJhuCWMtfdO0C+sQH543fjn0=; b=F3RKE5EGx/7YWD7wn6x3Uqz5M/fYQPyh/Gc57T2quiXHwQo2EcyR9EhNFQSYxzIx+l Nyd7CiEVhAL/rmVQXebNb55Tv2iWE+BwAsZHxTrfRZM76dfFn25jp5isa0iJu0W6FPOB P0cTVBd5bARximm3/Y0fYY8oO5LzOBHgMOHedp0G7sKC+A1M2uaUcF+CIwrSNDrKARa0 Lwuem0BQga9ew9NhBxyO5ZFQG3tuPny4brNfhZgvzhvXGVlrhwpwwUvcjQoe8IUxtEqt ZqIRcsS9kkhrXTs89vekYZsBtwUgRE6y6/a0DhIDHT9Wi6Qljs+6vYrzYNdzSiET06I+ c/6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704285770; x=1704890570; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/BpwCSw42VDWV3EnHxqnJhuCWMtfdO0C+sQH543fjn0=; b=QlO6E7TOHoYDb6ohwPRmFqTGZecVclV+ol8zB4kr7PBdIK5yztLftq0GJKnDWibfrw MkfIdHUbxkxbiatpM12KG68igOWWeutjH4TkX8cqpHNyZLLt95U8pwUUNStgfb512MvB FY1Fw5F1q5UKvYjb/NMC9oNpYGnnKgbWPmtXJDVFYlwmhDNSS1RVdcvaNKqGdtyOW8yc YiySutjyVo2fBreUbr4miQJ5ImjAtHFymhw/yprMCGWVr7FCD9GJ0YoGvXIvkCrXTSnM JDRe1gjNObWHWvU3euJxSLPreMmBu/HPz4PLiIwlpRkDfuZLIfIZgsBg1NkbSTGM03VZ 4pLQ== X-Gm-Message-State: AOJu0Yy/Ec0sJNpgIaq6J1tIx6TLOGCfr4JBHXUqtIRgUCaxXZ8CTPFB nQ5XzylLqF2tu84NNStYcCe3lj8D34I= X-Received: by 2002:a17:90a:4708:b0:280:11e2:12d6 with SMTP id h8-20020a17090a470800b0028011e212d6mr6733016pjg.45.1704285770416; Wed, 03 Jan 2024 04:42:50 -0800 (PST) Received: from Thaum. ([203.166.236.30]) by smtp.gmail.com with ESMTPSA id h20-20020a17090ac39400b0028ceab6ea3dsm1358812pjt.52.2024.01.03.04.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:42:49 -0800 (PST) Message-ID: <65955649.170a0220.e1f37.25c3@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 3 Jan 2024 23:42:43 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH v2] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899] References: <659490fd.170a0220.1ce2e.503a@mx.google.com> <65949213.a70a0220.2947.d85b@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <65949213.a70a0220.2947.d85b@mx.google.com> X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787020253152730484 X-GMAIL-MSGID: 1787073204162733279 Linaro CI tells me that this patch caused regressions on ARM. I don't have an ARM machine available to test on, but it appears to have been caused by attempting to stream vtables as static data members, and ARM having different behaviour with regards to when DECL_INTERFACE_KNOWN is marked on vtables. I don't think treating vtables as static members here is desirable anyway, though, so this version of the patch explicitly ignores them. Manually checking the assembly output for some of the noted regressions on ARM with a cross-compiler, this seems to have worked. Otherwise bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk if it passes Linaro CI on ARM this time? -- >8 -- Static data members marked 'inline' should be emitted in TUs where they are ODR-used. We need to make sure that statics imported from modules are correctly added to the 'pending_statics' map so that they get emitted if needed, otherwise the attached testcase fails to link. PR c++/112899 gcc/cp/ChangeLog: * cp-tree.h (note_variable_template_instantiation): Rename to... (note_static_storage_variable): ...this. * decl2.cc (note_variable_template_instantiation): Rename to... (note_static_storage_variable): ...this. * pt.cc (instantiate_decl): Rename usage of above function. * module.cc (trees_in::read_var_def): Remember pending statics that we stream in. gcc/testsuite/ChangeLog: * g++.dg/modules/init-4_a.C: New test. * g++.dg/modules/init-4_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 2 +- gcc/cp/decl2.cc | 4 ++-- gcc/cp/module.cc | 5 +++++ gcc/cp/pt.cc | 2 +- gcc/testsuite/g++.dg/modules/init-4_a.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/init-4_b.C | 11 +++++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/init-4_a.C create mode 100644 gcc/testsuite/g++.dg/modules/init-4_b.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1979572c365..ebd2850599a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7113,7 +7113,7 @@ extern tree maybe_get_tls_wrapper_call (tree); extern void mark_needed (tree); extern bool decl_needed_p (tree); extern void note_vague_linkage_fn (tree); -extern void note_variable_template_instantiation (tree); +extern void note_static_storage_variable (tree); extern tree build_artificial_parm (tree, tree, tree); extern bool possibly_inlined_p (tree); extern int parm_index (tree); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 0850d3f5bce..241216b0dfe 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -910,10 +910,10 @@ note_vague_linkage_fn (tree decl) vec_safe_push (deferred_fns, decl); } -/* As above, but for variable template instantiations. */ +/* As above, but for variables with static storage duration. */ void -note_variable_template_instantiation (tree decl) +note_static_storage_variable (tree decl) { vec_safe_push (pending_statics, decl); } diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 0bd46414da9..7edc0e37af0 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11752,6 +11752,11 @@ trees_in::read_var_def (tree decl, tree maybe_template) DECL_INITIALIZED_P (decl) = true; if (maybe_dup && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (maybe_dup)) DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; + if (DECL_CONTEXT (decl) + && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (decl)) + && !DECL_TEMPLATE_INFO (decl) + && !DECL_VTABLE_OR_VTT_P (decl)) + note_static_storage_variable (decl); } DECL_INITIAL (decl) = init; if (!dyn_init) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index f7063e09581..ce498750758 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27150,7 +27150,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) { set_instantiating_module (d); if (variable_template_p (gen_tmpl)) - note_variable_template_instantiation (d); + note_static_storage_variable (d); instantiate_body (td, args, d, false); } diff --git a/gcc/testsuite/g++.dg/modules/init-4_a.C b/gcc/testsuite/g++.dg/modules/init-4_a.C new file mode 100644 index 00000000000..e0eb97b474e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-4_a.C @@ -0,0 +1,9 @@ +// PR c++/112899 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi M } + +export module M; + +export struct A { + static constexpr int x = -1; +}; diff --git a/gcc/testsuite/g++.dg/modules/init-4_b.C b/gcc/testsuite/g++.dg/modules/init-4_b.C new file mode 100644 index 00000000000..d28017a1d14 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-4_b.C @@ -0,0 +1,11 @@ +// PR c++/112899 +// { dg-module-do run } +// { dg-additional-options "-fmodules-ts" } + +import M; + +int main() { + const int& x = A::x; + if (x != -1) + __builtin_abort(); +}