From: Nathan Sidwell <nathan@acm.org>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Cc: jason@redhat.com
Subject: Re: [PATCH] c++ modules: static var in inline function [PR104433]
Date: Fri, 7 Oct 2022 07:23:33 -0400 [thread overview]
Message-ID: <28d94bfb-5c22-f7e1-f479-1daf9d0748da@acm.org> (raw)
In-Reply-To: <20221006161916.4118820-1-ppalka@redhat.com>
On 10/6/22 12:19, Patrick Palka wrote:
> The below testcase fails to link with the error
>
> undefined reference to `f()::y'
>
> ultimately because during stream out for the static VAR_DECL y we
> override DECL_EXTERNAL to true, which later during IPA confuses
> symbol_table::remove_unreachable_nodes into thinking it's safe
> to not emit the symbol.
>
> The streaming code in question already avoids overriding DECL_EXTERNAL
> here for DECL_VAR_DECLARED_INLINE_P vars, so it seems natural to do the
> same for static vars from an DECL_DECLARED_INLINE_P function scope.
>
> After this patch (and r13-3134-g09df0d8b14dda6), the following now
> links:
>
> import <memory>;
> int main() { std::make_shared<int>(); }
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
yeah, that's correct -- these are just as inline
>
> PR c++/104433
>
> gcc/cp/ChangeLog:
>
> * module.cc (trees_out::core_bools): Don't override
> DECL_EXTERNAL to true for static variables from an inline
> function.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/static-2_a.H: New test.
> * g++.dg/modules/static-2_b.C: New test.
> ---
> gcc/cp/module.cc | 3 +++
> gcc/testsuite/g++.dg/modules/static-2_a.H | 8 ++++++++
> gcc/testsuite/g++.dg/modules/static-2_b.C | 9 +++++++++
> 3 files changed, 20 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/modules/static-2_a.H
> create mode 100644 gcc/testsuite/g++.dg/modules/static-2_b.C
>
> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
> index 79cbb346ffa..11f68794cd2 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -5397,6 +5397,9 @@ trees_out::core_bools (tree t)
>
> case VAR_DECL:
> if (TREE_PUBLIC (t)
> + && !(TREE_STATIC (t)
> + && DECL_FUNCTION_SCOPE_P (t)
> + && DECL_DECLARED_INLINE_P (DECL_CONTEXT (t)))
> && !DECL_VAR_DECLARED_INLINE_P (t))
> is_external = true;
> break;
> diff --git a/gcc/testsuite/g++.dg/modules/static-2_a.H b/gcc/testsuite/g++.dg/modules/static-2_a.H
> new file mode 100644
> index 00000000000..b4546932a12
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/static-2_a.H
> @@ -0,0 +1,8 @@
> +// PR c++/104433
> +// { dg-additional-options -fmodule-header }
> +// { dg-module-cmi {} }
> +
> +inline int* f() {
> + static int y = 0;
> + return &y;
> +}
> diff --git a/gcc/testsuite/g++.dg/modules/static-2_b.C b/gcc/testsuite/g++.dg/modules/static-2_b.C
> new file mode 100644
> index 00000000000..bfd35b0fc15
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/static-2_b.C
> @@ -0,0 +1,9 @@
> +// PR c++/104433
> +// { dg-additional-options -fmodules-ts }
> +// { dg-do link }
> +
> +import "static-2_a.H";
> +
> +int main() {
> + f();
> +}
--
Nathan Sidwell
prev parent reply other threads:[~2022-10-07 11:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 16:19 Patrick Palka
2022-10-07 11:23 ` Nathan Sidwell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28d94bfb-5c22-f7e1-f479-1daf9d0748da@acm.org \
--to=nathan@acm.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=ppalka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).