public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6527] c++: Fix up ICE in emit_support_tinfo_1 [PR109042]
@ 2023-03-07 15:29 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-03-07 15:29 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0d573c1f002fa77a4483aa9ebe310746a313082e
commit r13-6527-g0d573c1f002fa77a4483aa9ebe310746a313082e
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Mar 7 16:28:20 2023 +0100
c++: Fix up ICE in emit_support_tinfo_1 [PR109042]
In my recent rtti.cc change I assumed when emitting the support tinfos
that the tinfos for the fundamental types haven't been created yet.
Normally (in libsupc++.a (fundamental_type_info.o)) that is the case,
but as can be seen on the testcase, one can violate it by using typeid
etc. in the same TU and do it before ~__fundamental_type_info ()
definition.
The following patch fixes that by popping from unemitted_tinfo_decls
only in the normal case when it is there, and treating non-NULL
DECL_INITIAL on a tinfo node as indication that emit_tinfo_decl has
processed it already.
2023-03-07 Jakub Jelinek <jakub@redhat.com>
PR c++/109042
* rtti.cc (emit_support_tinfo_1): Don't assert that last
unemitted_tinfo_decls element is tinfo, instead pop from it only in
that case.
* decl2.cc (c_parse_final_cleanups): Don't call emit_tinfo_decl
for unemitted_tinfO_decls which have already non-NULL DECL_INITIAL.
* g++.dg/rtti/pr109042.C: New test.
Diff:
---
gcc/cp/decl2.cc | 2 +-
gcc/cp/rtti.cc | 13 +++++++++++--
gcc/testsuite/g++.dg/rtti/pr109042.C | 20 ++++++++++++++++++++
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 31dbb4d9ebb..387e24542cd 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -4982,7 +4982,7 @@ c_parse_final_cleanups (void)
get emitted. */
for (i = unemitted_tinfo_decls->length ();
unemitted_tinfo_decls->iterate (--i, &t);)
- if (emit_tinfo_decl (t))
+ if (DECL_INITIAL (t) || emit_tinfo_decl (t))
{
reconsider = true;
unemitted_tinfo_decls->unordered_remove (i);
diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc
index 2a253a43861..7878929c246 100644
--- a/gcc/cp/rtti.cc
+++ b/gcc/cp/rtti.cc
@@ -1581,10 +1581,19 @@ emit_support_tinfo_1 (tree bltn)
/* Emit it right away if not emitted already. */
if (DECL_INITIAL (tinfo) == NULL_TREE)
{
- gcc_assert (unemitted_tinfo_decls->last () == tinfo);
bool ok = emit_tinfo_decl (tinfo);
gcc_assert (ok);
- unemitted_tinfo_decls->pop ();
+ /* When compiling libsupc++.a (fundamental_type_info.o),
+ unemitted_tinfo_decls->last () will be tinfo, so pop it
+ from the vector as it is emitted now. If one uses typeid
+ etc. in the same TU as the definition of
+ ~fundamental_type_info (), the tinfo might be emitted
+ already earlier, in such case keep it in the vector
+ (as otherwise we'd need to walk the whole vector) and
+ let c_parse_final_cleanups ignore it when it will have
+ non-NULL DECL_INITIAL. */
+ if (unemitted_tinfo_decls->last () == tinfo)
+ unemitted_tinfo_decls->pop ();
}
}
}
diff --git a/gcc/testsuite/g++.dg/rtti/pr109042.C b/gcc/testsuite/g++.dg/rtti/pr109042.C
new file mode 100644
index 00000000000..af448f74a99
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/pr109042.C
@@ -0,0 +1,20 @@
+// PR c++/109042
+// { dg-do compile }
+
+namespace std { class type_info {}; }
+
+std::type_info
+foo ()
+{
+ return typeid (void);
+}
+
+namespace __cxxabiv1 {
+ struct __fundamental_type_info {
+ virtual ~__fundamental_type_info ();
+ };
+
+ __fundamental_type_info::~__fundamental_type_info ()
+ {
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-07 15:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 15:29 [gcc r13-6527] c++: Fix up ICE in emit_support_tinfo_1 [PR109042] Jakub Jelinek
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).