Commit fa7b533b by Zack Weinberg Committed by Zack Weinberg

tree.c (tree_vec_elt_check_failed): New function.

        * tree.c (tree_vec_elt_check_failed): New function.
        * tree.h (TREE_VEC_ELT_CHECK): New checking macro.
        (TREE_VEC_ELT): Use it.

        * tree-inline.c (optimize_inline_calls): Don't copy a
        zero-length vector.
cp:
        * search.c (dfs_push_decls): Do not try to reorder elements
        3..n of method_vec if method_vec has only two elements.
        Reverse order of two tests to avoid accessing unallocated
        memory.

From-SVN: r59114
parent 9fc910d1
2002-11-14 Zack Weinberg <zack@codesourcery.com>
* tree.c (tree_vec_elt_check_failed): New function.
* tree.h (TREE_VEC_ELT_CHECK): New checking macro.
(TREE_VEC_ELT): Use it.
* tree-inline.c (optimize_inline_calls): Don't copy a
zero-length vector.
2002-11-14 Gabriel Dos Reis <gdr@integrable-solutions.net> 2002-11-14 Gabriel Dos Reis <gdr@integrable-solutions.net>
* diagnostic.c (sorry): Don't repeat "sorry, unimplemented" text. * diagnostic.c (sorry): Don't repeat "sorry, unimplemented" text.
......
2002-11-14 Zack Weinberg <zack@codesourcery.com>
* search.c (dfs_push_decls): Do not try to reorder elements
3..n of method_vec if method_vec has only two elements.
Reverse order of two tests to avoid accessing unallocated
memory.
2002-11-14 Mark Mitchell <mark@codesourcery.com> 2002-11-14 Mark Mitchell <mark@codesourcery.com>
* class.c (dfs_find_final_overrider): Adjust so that the most * class.c (dfs_find_final_overrider): Adjust so that the most
......
...@@ -2544,7 +2544,8 @@ dfs_push_decls (binfo, data) ...@@ -2544,7 +2544,8 @@ dfs_push_decls (binfo, data)
method_vec = (CLASS_TYPE_P (type) method_vec = (CLASS_TYPE_P (type)
? CLASSTYPE_METHOD_VEC (type) : NULL_TREE); ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
if (method_vec)
if (method_vec && TREE_VEC_LENGTH (method_vec) >= 3)
{ {
tree *methods; tree *methods;
tree *end; tree *end;
...@@ -2553,7 +2554,7 @@ dfs_push_decls (binfo, data) ...@@ -2553,7 +2554,7 @@ dfs_push_decls (binfo, data)
end = TREE_VEC_END (method_vec); end = TREE_VEC_END (method_vec);
for (methods = &TREE_VEC_ELT (method_vec, 2); for (methods = &TREE_VEC_ELT (method_vec, 2);
*methods && methods != end; methods < end && *methods;
methods++) methods++)
setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)), setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
/*type_binding_p=*/0); /*type_binding_p=*/0);
......
...@@ -1367,6 +1367,7 @@ optimize_inline_calls (fn) ...@@ -1367,6 +1367,7 @@ optimize_inline_calls (fn)
{ {
tree ifn = make_tree_vec (VARRAY_ACTIVE_SIZE (id.inlined_fns)); tree ifn = make_tree_vec (VARRAY_ACTIVE_SIZE (id.inlined_fns));
if (VARRAY_ACTIVE_SIZE (id.inlined_fns))
memcpy (&TREE_VEC_ELT (ifn, 0), &VARRAY_TREE (id.inlined_fns, 0), memcpy (&TREE_VEC_ELT (ifn, 0), &VARRAY_TREE (id.inlined_fns, 0),
VARRAY_ACTIVE_SIZE (id.inlined_fns) * sizeof (tree)); VARRAY_ACTIVE_SIZE (id.inlined_fns) * sizeof (tree));
DECL_INLINED_FNS (fn) = ifn; DECL_INLINED_FNS (fn) = ifn;
......
...@@ -4665,6 +4665,22 @@ tree_class_check_failed (node, cl, file, line, function) ...@@ -4665,6 +4665,22 @@ tree_class_check_failed (node, cl, file, line, function)
tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
} }
/* Similar to above, except that the check is for the bounds of a TREE_VEC's
(dynamically sized) vector. */
void
tree_vec_elt_check_failed (idx, len, file, line, function)
int idx;
int len;
const char *file;
int line;
const char *function;
{
internal_error
("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
idx + 1, len, function, trim_filename (file), line);
}
#endif /* ENABLE_TREE_CHECKING */ #endif /* ENABLE_TREE_CHECKING */
/* For a new vector type node T, build the information necessary for /* For a new vector type node T, build the information necessary for
......
...@@ -317,12 +317,26 @@ struct tree_common GTY(()) ...@@ -317,12 +317,26 @@ struct tree_common GTY(())
__FUNCTION__); \ __FUNCTION__); \
__t; }) __t; })
#define TREE_VEC_ELT_CHECK(t, i) __extension__ \
(*({const tree __t = t; \
const int __i = (i); \
if (TREE_CODE (__t) != TREE_VEC) \
tree_check_failed (__t, TREE_VEC, \
__FILE__, __LINE__, __FUNCTION__); \
if (__i < 0 || __i >= __t->vec.length) \
tree_vec_elt_check_failed (__i, __t->vec.length, \
__FILE__, __LINE__, __FUNCTION__); \
&__t->vec.a[__i]; }))
extern void tree_check_failed PARAMS ((const tree, enum tree_code, extern void tree_check_failed PARAMS ((const tree, enum tree_code,
const char *, int, const char *)) const char *, int, const char *))
ATTRIBUTE_NORETURN; ATTRIBUTE_NORETURN;
extern void tree_class_check_failed PARAMS ((const tree, int, extern void tree_class_check_failed PARAMS ((const tree, int,
const char *, int, const char *)) const char *, int, const char *))
ATTRIBUTE_NORETURN; ATTRIBUTE_NORETURN;
extern void tree_vec_elt_check_failed PARAMS ((int, int, const char *,
int, const char *))
ATTRIBUTE_NORETURN;
#else /* not ENABLE_TREE_CHECKING, or not gcc */ #else /* not ENABLE_TREE_CHECKING, or not gcc */
...@@ -330,6 +344,7 @@ extern void tree_class_check_failed PARAMS ((const tree, int, ...@@ -330,6 +344,7 @@ extern void tree_class_check_failed PARAMS ((const tree, int,
#define TREE_CLASS_CHECK(t, code) (t) #define TREE_CLASS_CHECK(t, code) (t)
#define CST_OR_CONSTRUCTOR_CHECK(t) (t) #define CST_OR_CONSTRUCTOR_CHECK(t) (t)
#define EXPR_CHECK(t) (t) #define EXPR_CHECK(t) (t)
#define TREE_VEC_ELT_CHECK(t, i) ((t)->vec.a[i])
#endif #endif
...@@ -810,10 +825,11 @@ struct tree_list GTY(()) ...@@ -810,10 +825,11 @@ struct tree_list GTY(())
/* In a TREE_VEC node. */ /* In a TREE_VEC node. */
#define TREE_VEC_LENGTH(NODE) (TREE_VEC_CHECK (NODE)->vec.length) #define TREE_VEC_LENGTH(NODE) (TREE_VEC_CHECK (NODE)->vec.length)
#define TREE_VEC_ELT(NODE,I) (TREE_VEC_CHECK (NODE)->vec.a[I])
#define TREE_VEC_END(NODE) \ #define TREE_VEC_END(NODE) \
((void) TREE_VEC_CHECK (NODE), &((NODE)->vec.a[(NODE)->vec.length])) ((void) TREE_VEC_CHECK (NODE), &((NODE)->vec.a[(NODE)->vec.length]))
#define TREE_VEC_ELT(NODE,I) TREE_VEC_ELT_CHECK (NODE, I)
struct tree_vec GTY(()) struct tree_vec GTY(())
{ {
struct tree_common common; struct tree_common common;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment