This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix rtti ICE (4.1 regression, PR c++/23947)


Hi!

Since Nathan's 2005-06-15 rtti patch the following testcase crashes
on HEAD.
The problem is that in some cases the tinfo_descs vector is reallocated,
but get_pseudo_ti_init keeps holding pointers into the old array, which
in case of luck might be the same, but without luck can contain garbage
as well.  I have spotted just two places where a tinfo_s * pointer
into the tinfo_descs vector can be live accross reallocation,
which can happen when calling get_tinfo_ptr via.
get_tinfo_decl/get_pseudo_ti_index.
Ok for HEAD if bootstrap/regtesting succeeds (just started)?

Alternatively, rtti.c could stop passing around tinfo_s *
pointers and pass indexes into the tinfo_descs vector instead
and just use VEC_index (tinfo_s, tinfo_descs, xx) immediately
before each use.

2005-09-20  Jakub Jelinek  <jakub@redhat.com>

	PR c++/23947
	* rtti.c (get_pseudo_ti_init): Recompute ti pointer after
	get_tinfo_ptr calls.

	* g++.dg/rtti/crash3.C: New test.

--- gcc/cp/rtti.c.jj	2005-09-20 12:54:59.000000000 +0200
+++ gcc/cp/rtti.c	2005-09-20 12:58:48.000000000 +0200
@@ -1020,7 +1020,9 @@ get_pseudo_ti_init (tree type, unsigned 
 	tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), 0);
 	tree tinfo = get_tinfo_ptr (BINFO_TYPE (base_binfo));
 	tree base_inits = tree_cons (NULL_TREE, tinfo, NULL_TREE);
-	
+
+	/* get_tinfo_ptr might have reallocated the tinfo_descs vector.  */
+	ti = VEC_index (tinfo_s, tinfo_descs, tk_index);
 	return class_initializer (ti, type, base_inits);
       }
 
@@ -1079,6 +1081,9 @@ get_pseudo_ti_init (tree type, unsigned 
 	base_inits = tree_cons (NULL_TREE,
 				build_int_cst (NULL_TREE, hint),
 				base_inits);
+
+	/* get_tinfo_ptr might have reallocated the tinfo_descs vector.  */
+	ti = VEC_index (tinfo_s, tinfo_descs, tk_index);
 	return class_initializer (ti, type, base_inits);
       }
     }
--- gcc/testsuite/g++.dg/rtti/crash3.C.jj	2005-09-20 13:06:25.000000000 +0200
+++ gcc/testsuite/g++.dg/rtti/crash3.C	2005-09-20 13:07:03.000000000 +0200
@@ -0,0 +1,10 @@
+// PR c++/23947
+// { dg-do compile }
+
+class A {};
+class B {};
+class C : public A, public B {};
+class D : public C {};
+void f () throw (D)
+{
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]