C++ PATCH: PR 12815
Mark Mitchell
mark@codesourcery.com
Tue Jan 6 00:55:00 GMT 2004
This patch fixes a code-gen problem in the C++ front end. Jason (some
while back) marked as all vtable references as TREE_CONSTANT, which
doesn't make sense. If the object isn't TREE_CONSTANT, and its
dynamic type is not known, then it's vtable entries are not
TREE_CONSTANT either, although they are TREE_READONLY. Jason, am I
missing something here?
Also, it's a bid lame to ever return a TREE_CONSTANT vtable entry. If
we know which vtable entry it is, we should just go find the right
entry in the array and use it; no need to go indexing around at all.
But, that's for another day...
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-01-05 Mark Mitchell <mark@codesourcery.com>
PR c++/12815
* class.c (build_vtbl_ref_1): Do not unconditionally mark vtable
references as constant.
2004-01-05 Mark Mitchell <mark@codesourcery.com>
PR c++/12815
* g++.dg/rtti/typeid4.C: New test.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.591
diff -c -5 -p -r1.591 class.c
*** cp/class.c 25 Dec 2003 16:28:50 -0000 1.591
--- cp/class.c 6 Jan 2004 00:49:27 -0000
*************** build_vtbl_ref_1 (tree instance, tree id
*** 453,463 ****
vtbl = build_vfield_ref (instance, basetype);
assemble_external (vtbl);
aref = build_array_ref (vtbl, idx);
! TREE_CONSTANT (aref) = 1;
return aref;
}
tree
--- 453,463 ----
vtbl = build_vfield_ref (instance, basetype);
assemble_external (vtbl);
aref = build_array_ref (vtbl, idx);
! TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
return aref;
}
tree
Index: testsuite/g++.dg/rtti/typeid4.C
===================================================================
RCS file: testsuite/g++.dg/rtti/typeid4.C
diff -N testsuite/g++.dg/rtti/typeid4.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/rtti/typeid4.C 6 Jan 2004 00:49:27 -0000
***************
*** 0 ****
--- 1,26 ----
+ // { dg-do run }
+ // { dg-options "-O2" }
+
+ #include <typeinfo>
+ #include <iostream>
+
+ struct A { virtual ~A () {} };
+
+ struct APtr
+ {
+ APtr (A* p) : p_ (p) { }
+ A& operator* () const { return *p_; }
+ A* p_;
+ };
+
+ int main ()
+ {
+ APtr ap (new A);
+ std::type_info const* const exp = &typeid (*ap);
+ for (bool cont = true; cont; cont = false)
+ {
+ std::cout << "inner: cont " << cont << std::endl;
+ if (exp) ;
+ }
+ }
+
More information about the Gcc-patches
mailing list