This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Off by one in vtables
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH]: Off by one in vtables
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Tue, 05 Jun 2001 12:58:58 +0100
- Organization: Codesourcery LLC
Hi,
I've installed the attached on both branch and mainline.
It fixes three off-by-one errors when declaring array index types.
The value to use is the value of the highest index, not the number
of elements in the array.
booted & tested on i686-pc-linux-gnu.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-06-05 Nathan Sidwell <nathan@codesourcery.com>
* class.c (layout_vtable_decl): Fix off by one error on
build_index_type.
(build_vtt): Likewise.
(build_ctor_vtbl_group): Likewise.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.358.2.19
diff -c -3 -p -r1.358.2.19 class.c
*** class.c 2001/06/05 07:47:01 1.358.2.19
--- class.c 2001/06/05 08:11:48
*************** layout_vtable_decl (binfo, n)
*** 2461,2473 ****
tree binfo;
int n;
{
- tree itype;
tree atype;
tree vtable;
- itype = size_int (n);
atype = build_cplus_array_type (vtable_entry_type,
! build_index_type (itype));
layout_type (atype);
/* We may have to grow the vtable. */
--- 2461,2471 ----
tree binfo;
int n;
{
tree atype;
tree vtable;
atype = build_cplus_array_type (vtable_entry_type,
! build_index_type (size_int (n - 1)));
layout_type (atype);
/* We may have to grow the vtable. */
*************** layout_virtual_bases (t, offsets)
*** 4871,4877 ****
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), BITS_PER_UNIT);
/* Go through the virtual bases, allocating space for each virtual
! base that is not already a primary base class. Under the new
ABI, these are allocated according to a depth-first left-to-right
postorder traversal; in the new ABI, inheritance graph order is
used instead. */
--- 4869,4875 ----
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), BITS_PER_UNIT);
/* Go through the virtual bases, allocating space for each virtual
! base that is not already a primary base class. Under the old
ABI, these are allocated according to a depth-first left-to-right
postorder traversal; in the new ABI, inheritance graph order is
used instead. */
*************** build_vtt (t)
*** 7165,7171 ****
return;
/* Figure out the type of the VTT. */
! type = build_index_type (size_int (list_length (inits)));
type = build_cplus_array_type (const_ptr_type_node, type);
/* Now, build the VTT object itself. */
--- 7163,7169 ----
return;
/* Figure out the type of the VTT. */
! type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (const_ptr_type_node, type);
/* Now, build the VTT object itself. */
*************** build_ctor_vtbl_group (binfo, t)
*** 7484,7490 ****
inits = TREE_VALUE (list);
/* Figure out the type of the construction vtable. */
! type = build_index_type (size_int (list_length (inits)));
type = build_cplus_array_type (vtable_entry_type, type);
TREE_TYPE (vtbl) = type;
--- 7483,7489 ----
inits = TREE_VALUE (list);
/* Figure out the type of the construction vtable. */
! type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (vtable_entry_type, type);
TREE_TYPE (vtbl) = type;