:Re: [PATCH v2] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899]
Message ID | 2c3536c9-623a-8e02-45ea-8aaddb4ff5f5@idea |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5814789dyb; Thu, 4 Jan 2024 11:17:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQ5StTATqHOOnTYP1sjnvH+g51L7YRqaXGzdwQvZVMG9KrGryI82lfw90d2yj5p6+D1Gvp X-Received: by 2002:a05:6214:27cb:b0:67f:3c4b:a9b8 with SMTP id ge11-20020a05621427cb00b0067f3c4ba9b8mr1011384qvb.70.1704395840686; Thu, 04 Jan 2024 11:17:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704395840; cv=pass; d=google.com; s=arc-20160816; b=mgTJEbCGeJ4lb7EjAxAKFFD4vO2YDVXkWaqD0nkCKMo3o2IycfSLB9NDcagmuQle2I EEoAsFDKHd7PwoL+i7j8zg5O51YylwYONdc8GBRlSwSUqsPP/MsIW2qSef7uvGcvEUVy VSnJcw9UjruskFgv3yENlOe6mqphoU42vR1xOGjxBv9U3G8MXvM9PlmKBLc4wdYQ/cFg BRare8mr1cUocchVCRBhfJmRnztwdukVt05zg/Pabb6Bun+d47RQFMl8pAu4QQ5LjBaE fnoYQ+xxAOggWiryJg6q8yvX6c+1e61ATInjc4GnVYBeiJNQlQyGqfr+wFi4GbgAZqZP 6C8A== 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:mime-version:references :message-id:in-reply-to:subject:cc:to:date:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=V1qHs9xwfS8p+dWZR0K0Q0Eb4VjoNLL2IomnnSrVXeM=; fh=2lYndfrrlCvWy4uskKYRI82hYTUQOINBDhYXmm+SP2s=; b=0UFZlM52YcWwbDgJzAhDA5qhkHmkVbzA+R8ZaP7oCNik+V0p4BFs9oQN4IYlVqDNMf M4m5woeX2EYv9e9vTWo4t1CYj3L0zLu1NlVMDdXZ/B0JfMG58vNu9XINKAFvacZ5zGJz 1gZoe6WpdNorAThwbsvJMHYOglZCpI/PJtRBDZBOiH+cTMeDZEmNlWxVrrxjJ+5PtoIw vNYHuduC4sGTuDuLeaCWC4fTY50695bxQRXamhe+PFIbae+Z21W4Y2pPRjW66X1RaWaF slnBuCbtpg7xJvS7i36F5qyt4Rfb7kFQiEYoBaQzv7sBTiZtrT+rAUW86SanYPX38iPb wlrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QtFKYM0L; 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=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h3-20020a0cf403000000b0067ed2267b72si89508qvl.275.2024.01.04.11.17.20 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:17:20 -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=@redhat.com header.s=mimecast20190719 header.b=QtFKYM0L; 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=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62F5E3858006 for <ouuuleilei@gmail.com>; Thu, 4 Jan 2024 19:17:20 +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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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-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 <ppalka@redhat.com> X-Google-Original-From: Patrick Palka <patrick@idea> Date: Thu, 4 Jan 2024 14:16:27 -0500 (EST) To: Nathaniel Shead <nathanieloshead@gmail.com> cc: gcc-patches@gcc.gnu.org, Jason Merrill <jason@redhat.com>, Nathan Sidwell <nathan@acm.org>, Patrick Palka <ppalka@redhat.com> 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 Content-Type: text/plain; charset=US-ASCII 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787188573185348479 X-GMAIL-MSGID: 1787188573185348479 |
Series |
:Re: [PATCH v2] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Patrick Palka
Jan. 4, 2024, 7:16 p.m. UTC
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 <nathanieloshead@gmail.com> > --- > 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); }