This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Plug memory leak
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 19 Nov 2002 21:13:43 -0800
- Subject: C++ PATCH: Plug memory leak
- Reply-to: mark at codesourcery dot com
This patch fixes a memory leak in G++ and also speeds up certain
traversals of inheritance graphs with virtual bases.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-11-19 Mark Mitchell <mark@codesourcery.com>
* pt.c (for_each_template_parm): Free allocated memory.
* search.c (is_subobject_of_p_1): New function.
(is_subobject_of_p): Avoid walking virtual bases multiple times.
Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.630
diff -c -5 -p -r1.630 pt.c
*** pt.c 9 Nov 2002 11:53:16 -0000 1.630
--- pt.c 20 Nov 2002 03:19:15 -0000
*************** for_each_template_parm (t, fn, data, vis
*** 4532,4541 ****
--- 4532,4542 ----
tree_fn_t fn;
void* data;
htab_t visited;
{
struct pair_fn_data pfd;
+ int result;
/* Set up. */
pfd.fn = fn;
pfd.data = data;
*************** for_each_template_parm (t, fn, data, vis
*** 4547,4560 ****
if (visited)
pfd.visited = visited;
else
pfd.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer,
NULL);
! return walk_tree (&t,
! for_each_template_parm_r,
! &pfd,
! NULL) != NULL_TREE;
}
int
uses_template_parms (t)
tree t;
--- 4548,4567 ----
if (visited)
pfd.visited = visited;
else
pfd.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer,
NULL);
! result = walk_tree (&t,
! for_each_template_parm_r,
! &pfd,
! NULL) != NULL_TREE;
!
! /* Clean up. */
! if (!visited)
! htab_delete (pfd.visited);
!
! return result;
}
int
uses_template_parms (t)
tree t;
Index: search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.240
diff -c -5 -p -r1.240 search.c
*** search.c 4 Nov 2002 01:45:55 -0000 1.240
--- search.c 20 Nov 2002 03:19:17 -0000
*************** struct vbase_info
*** 80,89 ****
--- 80,90 ----
tree inits;
};
static tree lookup_field_1 PARAMS ((tree, tree));
static int is_subobject_of_p PARAMS ((tree, tree, tree));
+ static int is_subobject_of_p_1 PARAMS ((tree, tree, tree));
static tree dfs_check_overlap PARAMS ((tree, void *));
static tree dfs_no_overlap_yet PARAMS ((tree, void *));
static base_kind lookup_base_r
PARAMS ((tree, tree, base_access, int, int, int, tree *));
static int dynamic_cast_base_recurse PARAMS ((tree, tree, int, tree *));
*************** accessible_p (type, decl)
*** 1097,1113 ****
assert_canonical_unmarked (binfo);
return t != NULL_TREE;
}
! /* Routine to see if the sub-object denoted by the binfo PARENT can be
! found as a base class and sub-object of the object denoted by
! BINFO. MOST_DERIVED is the most derived type of the hierarchy being
! searched. */
static int
! is_subobject_of_p (parent, binfo, most_derived)
tree parent, binfo, most_derived;
{
tree binfos;
int i, n_baselinks;
--- 1098,1112 ----
assert_canonical_unmarked (binfo);
return t != NULL_TREE;
}
! /* Recursive helper funciton for is_subobject_of_p; see that routine
! for documentation of the parameters. */
static int
! is_subobject_of_p_1 (parent, binfo, most_derived)
tree parent, binfo, most_derived;
{
tree binfos;
int i, n_baselinks;
*************** is_subobject_of_p (parent, binfo, most_d
*** 1119,1139 ****
/* Iterate the base types. */
for (i = 0; i < n_baselinks; i++)
{
tree base_binfo = TREE_VEC_ELT (binfos, i);
! if (!CLASS_TYPE_P (TREE_TYPE (base_binfo)))
/* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
class there's no way to descend into it. */
continue;
! if (is_subobject_of_p (parent,
! CANONICAL_BINFO (base_binfo, most_derived),
! most_derived))
return 1;
}
return 0;
}
struct lookup_field_info {
/* The type in which we're looking. */
tree type;
--- 1118,1169 ----
/* Iterate the base types. */
for (i = 0; i < n_baselinks; i++)
{
tree base_binfo = TREE_VEC_ELT (binfos, i);
! tree base_type;
!
! base_type = TREE_TYPE (base_binfo);
! if (!CLASS_TYPE_P (base_type))
/* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
class there's no way to descend into it. */
continue;
! /* Avoid walking into the same virtual base more than once. */
! if (TREE_VIA_VIRTUAL (base_binfo))
! {
! if (CLASSTYPE_MARKED4 (base_type))
! return 0;
! SET_CLASSTYPE_MARKED4 (base_type);
! base_binfo = binfo_for_vbase (base_type, most_derived);
! }
!
! if (is_subobject_of_p_1 (parent, base_binfo, most_derived))
return 1;
}
return 0;
+ }
+
+ /* Routine to see if the sub-object denoted by the binfo PARENT can be
+ found as a base class and sub-object of the object denoted by
+ BINFO. MOST_DERIVED is the most derived type of the hierarchy being
+ searched. */
+
+ static int
+ is_subobject_of_p (tree parent, tree binfo, tree most_derived)
+ {
+ int result;
+ tree vbase;
+
+ result = is_subobject_of_p_1 (parent, binfo, most_derived);
+ /* Clear the mark bits on virtual bases. */
+ for (vbase = CLASSTYPE_VBASECLASSES (most_derived);
+ vbase;
+ vbase = TREE_CHAIN (vbase))
+ CLEAR_CLASSTYPE_MARKED4 (TREE_TYPE (TREE_VALUE (vbase)));
+
+ return result;
}
struct lookup_field_info {
/* The type in which we're looking. */
tree type;