From patchwork Thu Jan 4 19:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1882594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QtFKYM0L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T5btg21rpz1yQ5 for ; Fri, 5 Jan 2024 06:16:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24E693858431 for ; Thu, 4 Jan 2024 19:16:57 +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 C1BA53858D32 for ; Thu, 4 Jan 2024 19:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1BA53858D32 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 C1BA53858D32 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=1704395793; cv=none; b=Q2RbZqfaSe0njYMqFJ63EEqZWMX97o0NecTHDPA/kuiaFNU3KdIcqH7pAxZNooNlANhkZyOAxLkNeLj/kkQU3BPpVZv3Ets7DRA11Bty5+EDOqe3Bq3oTqEVebVdyazxG4cjR5/h8Tc+6yhYSbke7lFUiOHv1kv+nj6FmK7pU0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704395793; c=relaxed/simple; bh=/S3EOrckSg30xPkgGQ51i1Bf91lgLkNtbw8AkIWtJxk=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=IvMjKW8tH75NhPn/T3bWcH2YAUNTWb/8ATGREznw5p85+oEaiFw35NA69qeRpP2x+FXLxVpligI4GPR6NYTnE0OGrZ1e6VN7qsjq5pz9sSY/k7nYoHfFnheEa62+GPTJRFStOe676BPwqO9xNmclbfruEcpivlZz4JmHQhWps2Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704395791; 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: in-reply-to:in-reply-to:references:references; bh=V1qHs9xwfS8p+dWZR0K0Q0Eb4VjoNLL2IomnnSrVXeM=; b=QtFKYM0LJGEh6YN6OdUIDNyuudkWrxilfROFtvqV9cfYQ15UIb8lNz4MgGLTpbmTsLP5rn W2EJwezGhS7dZufA3HQjIALovJ2S2FRI+JzQBB2IygIjpQpc5XmZmVZthkJI77G99Yp3Vu Y+SfExnzgrimiDehG/rj6MLNwERZ1U0= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639--U-7Fp1xNX2cG7yXWZde8A-1; Thu, 04 Jan 2024 14:16:29 -0500 X-MC-Unique: -U-7Fp1xNX2cG7yXWZde8A-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6dc20b43230so936991a34.0 for ; Thu, 04 Jan 2024 11:16:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704395788; x=1705000588; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V1qHs9xwfS8p+dWZR0K0Q0Eb4VjoNLL2IomnnSrVXeM=; b=WxrEcokk/j8c4sAOdGyjBsUdre8ak8DSQIgUf8zJa50PtTZ7Nqie46LabpcuymzIUe s3joD22fmpLjbAbjb16o7SuZiQZE1SEkKGdq8tvyCJx6aIITNg2RzGnuG1AiZbDewfmz HZuSmfr9T2OkGmko6meZjF3DiBu7xeQPrrw9rK5+ui+Wpf7kEk5PKH5sZexMWZC86wro H3I5wIvnOHRXFOnDgLADQfjHxW6h8iOhncvzdGEPtAlpkxc68UXBQ/BVoAr/GJMBzxZc 0DghzRz85Y5eiuPhIYq4sOV8mrbo0wJOYjAAOvEe3UjBWIOGv/fYBYYtGw6fCNEf78YL MZcQ== X-Gm-Message-State: AOJu0YwBWF9gyPV1NrYUm+UvuH12LKSXIuFe5ug5BZ9cLFxR7gHlGD9r wfd4Y0ru+uONewaglNUglMEexF+bBBMzZ7z8A/dPIobKzcd5kxKxBeUAUpVPn7ZqIK0l/EukQ5F xqrBROkUhaKZHTlKKflXeXWHVpQ== X-Received: by 2002:a05:6870:898b:b0:1fa:ea74:ddc9 with SMTP id f11-20020a056870898b00b001faea74ddc9mr1128365oaq.10.1704395788601; Thu, 04 Jan 2024 11:16:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IF12f9Ux4qgb1ywRzxJ9s0Usb1oV23uyVCemT1Xt4xJFO3FXbMMBW5f0dIMzd/2CmL8Nrr2VQ== X-Received: by 2002:a05:6870:898b:b0:1fa:ea74:ddc9 with SMTP id f11-20020a056870898b00b001faea74ddc9mr1128357oaq.10.1704395788370; Thu, 04 Jan 2024 11:16:28 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id r15-20020a05620a03cf00b0077f289b92c6sm21698qkm.123.2024.01.04.11.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:16:28 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 4 Jan 2024 14:16:27 -0500 (EST) To: Nathaniel Shead cc: gcc-patches@gcc.gnu.org, Jason Merrill , Nathan Sidwell , Patrick Palka Subject: :Re: [PATCH v2] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899] In-Reply-To: <65955649.170a0220.e1f37.25c3@mx.google.com> Message-ID: <2c3536c9-623a-8e02-45ea-8aaddb4ff5f5@idea> References: <659490fd.170a0220.1ce2e.503a@mx.google.com> <65949213.a70a0220.2947.d85b@mx.google.com> <65955649.170a0220.e1f37.25c3@mx.google.com> 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org On Wed, 3 Jan 2024, Nathaniel Shead wrote: > 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. Seems reasonable to me Just FYI for anyone else wondering about namespace-scope variables, it seems during stream-in they're added to a separate 'static_decls' vector via add_module_namespace_decl which wrapup_namespace_globals later handles emitting their definitions, so it makes sense to me to have analogous handling for class-scope variables. > > 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); This is a latent issue/curiousity orthogonal to your patch, but it seems inconsistent that namespace-scope variable template instantiations get added to 'pending_statics' (which is intended for class-scope variables) rather than to 'static_decls' (which is intended for namespace-scope variables). I wonder if we should instead do: > 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(); > +} > -- > 2.43.0 > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 154ac76cb65..25921c97ffe 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27155,7 +27155,12 @@ 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); + { + if (DECL_CLASS_SCOPE_P (gen_tmpl)) + note_static_data_member (d); + else + vec_safe_push (static_decls, d); + } instantiate_body (td, args, d, false); }