Remove memory leak in handle_vector_size_attribute
Bernd Schmidt
bernds@redhat.com
Thu Apr 18 04:17:00 GMT 2002
While debugging some other altivec problems, I noticed that we create a
new type node each time handle_vector_size_attribute is called. This
patch plugs that memory leak.
Bootstrapped on i686-linux, and tested against ppc-eabisimaltivec. Two
altivec tests seem to have execution failures with or without the patch.
Bernd
* attribs.c (vector_type_node_list): New static variable.
(handle_vector_size_attribute): Use it to avoid generating a
new type node each time we are called.
Index: attribs.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/attribs.c,v
retrieving revision 1.20
diff -c -p -r1.20 attribs.c
*** attribs.c 29 Mar 2002 21:45:56 -0000 1.20
--- attribs.c 17 Apr 2002 18:21:51 -0000
*************** handle_deprecated_attribute (node, name,
*** 1268,1273 ****
--- 1268,1280 ----
return NULL_TREE;
}
+ /* Keep a list of vector type nodes we created in handle_vector_size_attribute,
+ to prevent us from duplicating type nodes unnecessarily.
+ The normal mechanism to prevent duplicates is to use type_hash_canon, but
+ since we want to distinguish types that are essentially identical (except
+ for their debug representation), we use a local list here. */
+ static tree vector_type_node_list = 0;
+
/* Handle a "vector_size" attribute; arguments as in
struct attribute_spec.handler. */
*************** handle_vector_size_attribute (node, name
*** 1281,1287 ****
{
unsigned HOST_WIDE_INT vecsize, nunits;
enum machine_mode mode, orig_mode, new_mode;
! tree type = *node, new_type;
*no_add_attrs = true;
--- 1288,1295 ----
{
unsigned HOST_WIDE_INT vecsize, nunits;
enum machine_mode mode, orig_mode, new_mode;
! tree type = *node, new_type = NULL_TREE;
! tree type_list_node;
*no_add_attrs = true;
*************** handle_vector_size_attribute (node, name
*** 1337,1347 ****
break;
}
! if (new_mode == VOIDmode)
! error ("no vector mode with the size and type specified could be found");
! else
{
! tree index, array, rt;
new_type = (*lang_hooks.types.type_for_mode) (new_mode,
TREE_UNSIGNED (type));
--- 1345,1378 ----
break;
}
! if (new_mode == VOIDmode)
{
! error ("no vector mode with the size and type specified could be found");
! return NULL_TREE;
! }
!
! for (type_list_node = vector_type_node_list; type_list_node;
! type_list_node = TREE_CHAIN (type_list_node))
! {
! tree other_type = TREE_VALUE (type_list_node);
! tree record = TYPE_DEBUG_REPRESENTATION_TYPE (other_type);
! tree fields = TYPE_FIELDS (record);
! tree field_type = TREE_TYPE (fields);
! tree array_type = TREE_TYPE (field_type);
! if (TREE_CODE (fields) != FIELD_DECL
! || TREE_CODE (field_type) != ARRAY_TYPE)
! abort ();
!
! if (TYPE_MODE (other_type) == mode && type == array_type)
! {
! new_type = other_type;
! break;
! }
! }
!
! if (new_type == NULL_TREE)
! {
! tree index, array, rt, list_node;
new_type = (*lang_hooks.types.type_for_mode) (new_mode,
TREE_UNSIGNED (type));
*************** handle_vector_size_attribute (node, name
*** 1367,1376 ****
layout_type (rt);
TYPE_DEBUG_REPRESENTATION_TYPE (new_type) = rt;
! /* Build back pointers if needed. */
! *node = vector_size_helper (*node, new_type);
}
!
return NULL_TREE;
}
--- 1398,1411 ----
layout_type (rt);
TYPE_DEBUG_REPRESENTATION_TYPE (new_type) = rt;
! list_node = build_tree_list (NULL, new_type);
! TREE_CHAIN (list_node) = vector_type_node_list;
! vector_type_node_list = list_node;
}
!
! /* Build back pointers if needed. */
! *node = vector_size_helper (*node, new_type);
!
return NULL_TREE;
}
More information about the Gcc-patches
mailing list