From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id C8CF03858D33; Fri, 3 Mar 2023 07:27:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8CF03858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677828454; bh=zC1rpwvLeYDzE+46G9dKGo0GwQjHf/cdAFhtQYdr2QU=; h=From:To:Subject:Date:From; b=FOf/HOAON3SZkjmi8t8+gnnDZIDXzMYxTXJXXDBl4C+WIjTDKwZZAxizIuWLxRZaj cSjcXkT594LqGO7t0/DUtVznTb7AkJwM5D0HoXyiAQNpkYLOI4PHtWYU2Si9Or+dBy oSIu8+curJ+fBN+oaii7DfVdWLTH+VAWFr6mgMxE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6438] debug/108772 - ICE with late debug generated with -flto X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 1e4122f1159ace52c114c011013adce25172d77b X-Git-Newrev: 33ca5c92dfa7e2f591a838bb768d9d6eea56793b Message-Id: <20230303072734.C8CF03858D33@sourceware.org> Date: Fri, 3 Mar 2023 07:27:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:33ca5c92dfa7e2f591a838bb768d9d6eea56793b commit r13-6438-g33ca5c92dfa7e2f591a838bb768d9d6eea56793b Author: Richard Biener Date: Wed Mar 1 10:01:10 2023 +0100 debug/108772 - ICE with late debug generated with -flto When combining -g1 with -flto we run into the DIE location annotation machinery for globals calling dwarf2out_late_global_decl but not having any early generated DIE for function scope statics. In this process we'd generate a limbo DIE since also the function scope doesn't have any early generated DIE. The limbo handling then tries to force a DIE for the context chain which ultimatively fails and ICEs at the std namespace decl because at -g1 we don't represent that. The following avoids this situation by making sure to never generate any DIEs from dwarf2out_late_global_decl in the in_lto_p path for function scope globals but rely on DIE generation for the function to output a DIE for the local static (which doesn't happen for -g1). I explored a lot of other options to fix this but in the end this seems to be the most spot-on fix with the least risk of unwanted effects. PR debug/108772 * dwarf2out.cc (dwarf2out_late_global_decl): Do not generate a DIE for a function scope static. * g++.dg/lto/pr108772_0.C: New testcase. Diff: --- gcc/dwarf2out.cc | 5 +++- gcc/testsuite/g++.dg/lto/pr108772_0.C | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 1f39df3b1e2..1711ad2c2da 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -27282,7 +27282,10 @@ dwarf2out_late_global_decl (tree decl) /* We may have to generate full debug late for LTO in case debug was not enabled at compile-time or the target doesn't support the LTO early debug scheme. */ - if (! die && in_lto_p) + if (! die && in_lto_p + /* Function scope variables are emitted when emitting the + DIE for the function. */ + && ! local_function_static (decl)) dwarf2out_decl (decl); else if (die) { diff --git a/gcc/testsuite/g++.dg/lto/pr108772_0.C b/gcc/testsuite/g++.dg/lto/pr108772_0.C new file mode 100644 index 00000000000..81f15a90a3e --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr108772_0.C @@ -0,0 +1,46 @@ +// { dg-lto-do link } +// { dg-require-effective-target shared } +// { dg-require-effective-target fpic } +// { dg-lto-options { "-flto -fPIC -shared -O1 -fimplicit-constexpr -g1" } } +// { dg-extra-ld-options "-shared" } + +namespace std { +struct _Sp_counted_base { + virtual void *_M_get_deleter(const int &); +}; +bool _S_eq(int); +struct _Sp_make_shared_tag { + static const int &_S_ti() { + static constexpr char __tag{}; + return reinterpret_cast(__tag); + } +}; +struct _Impl { + _Impl(int); +}; +int _Sp_counted_ptr_inplace___a; +struct _Sp_counted_ptr_inplace : _Sp_counted_base { + _Sp_counted_ptr_inplace() : _M_impl(_Sp_counted_ptr_inplace___a) {} + void *_M_get_deleter(const int &__ti) { + auto __ptr(_M_ptr()); + &__ti == &_Sp_make_shared_tag::_S_ti() || _S_eq(__ti); + return __ptr; + } + int *_M_ptr(); + _Impl _M_impl; +}; +struct __shared_count { + __shared_count(int, int) { _Sp_counted_ptr_inplace(); } +}; +int _M_ptr; +struct __shared_ptr { + template + __shared_ptr(_Alloc __tag) : _M_refcount(_M_ptr, __tag) {} + __shared_count _M_refcount; +}; +int shared_ptr___tag; +struct shared_ptr : __shared_ptr { + shared_ptr() : __shared_ptr(shared_ptr___tag) {} +}; +void ArgEq() { shared_ptr(); } +} // namespace std