[tree-ssa mudflap] patch
Frank Ch. Eigler
fche@redhat.com
Mon Sep 9 14:27:00 GMT 2002
Hi -
I'm committing the following patch. It's the usual mixture
of extensions & cleanup.
+++ gcc/ChangeLog.tree-ssa 9 Sep 2002 21:25:11 -0000
+2002-09-09 Frank Ch. Eigler <fche@redhat.com>
+
+ * tree-mudflap.c (mf_offset_expr_of_array_ref): Fold constants along
+ the way.
+ (mf_build_check_statement_for): Ditto. Flag new COMPONENT_REFs.
+ (mx_xfn_indirect_ref): Instrument COMPONENT_REFs specially. Tweak
+ ARRAY_REF instrumentation to reduce need of copying and recursion.
+
+++ libmudflap/ChangeLog 9 Sep 2002 21:25:12 -0000
+2002-09-09 Frank Ch. Eigler <fche@redhat.com>
+
+ * Makefile.am: Create test sources with #include, not cat>>.
+ * Makefile.in: Regenerated.
+ * test/buildtest.sh: Removed.
+ * test/driver.c (abort_handler, main): Be quiet.
Index: gcc/tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.12
diff -u -w -p -r1.1.2.12 tree-mudflap.c
--- gcc/tree-mudflap.c 6 Sep 2002 19:20:56 -0000 1.1.2.12
+++ gcc/tree-mudflap.c 9 Sep 2002 21:25:12 -0000
@@ -580,11 +580,11 @@ mf_offset_expr_of_array_ref (t, offset,
{
/* It's a sub-array-ref; recurse. */
- tree factor = build (PLUS_EXPR,
+ tree factor = fold (build (PLUS_EXPR,
integer_type_node,
integer_one_node,
TYPE_MAX_VALUE
- (TYPE_DOMAIN (TREE_TYPE (t))));
+ (TYPE_DOMAIN (TREE_TYPE (t)))));
tree child = TREE_OPERAND (t, 0);
tree next_offset = TREE_OPERAND (t, 1);
@@ -595,9 +595,11 @@ mf_offset_expr_of_array_ref (t, offset,
mx_flag (t);
return
- build (PLUS_EXPR, integer_type_node, offset,
- build (MULT_EXPR, integer_type_node, factor,
- mf_offset_expr_of_array_ref (child, next_offset, base)));
+ fold (build (PLUS_EXPR, integer_type_node, offset,
+ fold (build (MULT_EXPR, integer_type_node, factor,
+ mf_offset_expr_of_array_ref (child,
+ next_offset,
+ base)))));
}
else if ( TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE )
{
@@ -695,16 +697,16 @@ mf_build_check_statement_for (ptrvalue,
/* Quick validity check. */
t1_4_1 = build (BIT_IOR_EXPR, integer_type_node,
build (GT_EXPR, integer_type_node,
- build (COMPONENT_REF, mf_uintptr_type, /* __mf_elem->low */
+ mx_flag (build (COMPONENT_REF, mf_uintptr_type, /* __mf_elem->low */
mx_flag (build1 (INDIRECT_REF,
mf_cache_struct_type, t1_3_1)),
- TYPE_FIELDS (mf_cache_struct_type)),
+ TYPE_FIELDS (mf_cache_struct_type))),
t1_2a_1), /* __mf_base */
build (LT_EXPR, integer_type_node,
- build (COMPONENT_REF, mf_uintptr_type, /* __mf_elem->high */
+ mx_flag (build (COMPONENT_REF, mf_uintptr_type, /* __mf_elem->high */
mx_flag (build1 (INDIRECT_REF,
mf_cache_struct_type, t1_3_1)),
- TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type))),
+ TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type)))),
build (PLUS_EXPR, mf_uintptr_type, /* __mf_elem + sizeof(T) - 1 */
t1_2a_1,
fold (build (MINUS_EXPR, mf_uintptr_type,
@@ -774,6 +776,12 @@ mf_build_check_statement_for (ptrvalue,
(2) (ARRAY_REF ({ARRAY_REF ... (tree, indexM)}, indexN)) // tree[N][M][O]...
==> (as if)
(INDIRECT_REF (tree + (.... + sizeM*sizeO*indexO + sizeM*indexM + indexN))
+ ... except the base value for the check is &tree[0], not &tree[N][M][O]
+
+ (3) (COMPONENT_REF (INDIRECT_REF (tree), field))
+ ==> (as if)
+ (COMPONENT_REF (INDIRECT_REF (tree), field))
+ ... except the size value for the check is offsetof(field)+sizeof(field)-1
*/
@@ -788,7 +796,9 @@ mx_xfn_indirect_ref (t, continue_p, data
htab_t verboten = (htab_t) data;
#if 0
- fprintf (stderr, "expr=%s\n", tree_code_name [TREE_CODE (*t)]);
+ fprintf (stderr, "expr=%s: ", tree_code_name [TREE_CODE (*t)]);
+ print_c_tree (stderr, *t);
+ fprintf (stderr, "\n");
#endif
*continue_p = 1;
@@ -838,6 +848,7 @@ mx_xfn_indirect_ref (t, continue_p, data
offset_expr = mf_offset_expr_of_array_ref (TREE_OPERAND (*t,0),
TREE_OPERAND (*t,1),
&base_array);
+ /* walk_tree (& offset_expr, mf_mostly_copy_tree_r, NULL, NULL); */
/* We now have a tree representing the array in base_array,
and a tree representing the complete desired offset in
@@ -846,12 +857,13 @@ mx_xfn_indirect_ref (t, continue_p, data
base_obj_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND(*t,0)));
base_ptr_type = build_pointer_type (base_obj_type);
+ /* NB: Previously, this was (& base_array[0]) */
+ /* XXX: subset of default_conversion() for arrays */
check_ptr = mx_flag (build1 (ADDR_EXPR,
base_ptr_type,
- mx_flag (build (ARRAY_REF,
- base_obj_type,
- base_array, integer_zero_node))));
- walk_tree (& check_ptr, mf_mostly_copy_tree_r, NULL, NULL);
+ base_array));
+ /* walk_tree (& check_ptr, mf_mostly_copy_tree_r, NULL, NULL); */
+ TREE_ADDRESSABLE (base_array) = 1;
value_ptr = mx_flag (build1 (ADDR_EXPR,
base_ptr_type,
@@ -859,13 +871,12 @@ mx_xfn_indirect_ref (t, continue_p, data
walk_tree (& value_ptr, mf_mostly_copy_tree_r, NULL, NULL);
TREE_ADDRESSABLE (*t) = 1;
- check_size = build (MULT_EXPR,
+ check_size = fold (build (MULT_EXPR,
integer_type_node,
TYPE_SIZE_UNIT (base_obj_type),
- build (PLUS_EXPR, c_size_type_node,
+ fold (build (PLUS_EXPR, c_size_type_node,
integer_one_node,
- offset_expr));
- walk_tree (& check_size, mf_mostly_copy_tree_r, NULL, NULL);
+ offset_expr))));
/* In case we're instrumenting an expression like a[b[c]], the
following call is meant to eliminate the
@@ -896,6 +907,28 @@ mx_xfn_indirect_ref (t, continue_p, data
Note that we do not prevent recusion in walk_tree toward
subtrees of this node, in case of nested pointer expressions. */
mx_flag (*t);
+ break;
+
+ case COMPONENT_REF:
+ if (TREE_CODE (TREE_OPERAND (*t, 0)) == INDIRECT_REF)
+ {
+ tree *pointer = & TREE_OPERAND (TREE_OPERAND (*t, 0), 0);
+
+ tree field_offset = byte_position (TREE_OPERAND (*t, 1));
+ tree field_size = size_in_bytes (TREE_TYPE (TREE_OPERAND (*t, 1)));
+ tree check_size = fold (build (PLUS_EXPR, c_size_type_node,
+ field_offset, field_size));
+
+ *pointer =
+ mf_build_check_statement_for (*pointer,
+ *pointer,
+ check_size,
+ last_filename, last_lineno);
+
+ /* Don't instrument the nested INDIRECT_REF. */
+ mx_flag (TREE_OPERAND (*t, 0));
+ mx_flag (*t);
+ }
break;
}
Index: libmudflap/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/Makefile.am,v
retrieving revision 1.1.2.9
diff -u -w -p -r1.1.2.9 Makefile.am
--- libmudflap/Makefile.am 6 Sep 2002 19:04:43 -0000 1.1.2.9
+++ libmudflap/Makefile.am 9 Sep 2002 21:25:12 -0000
@@ -18,12 +18,13 @@ TESTS = test/fail1.x test/fail10.x test/
test/pass6.x test/pass7.x test/pass8.x test/pass9.x
-test/%.c: test/%-frag.c test/mf-driver.c test/buildtest.sh
+test/%.c: test/%-frag.c test/mf-driver.c
@mkdir -p test
- @cat $(srcdir)/test/mf-driver.c > $@
+ @echo '#include "'$(srcdir)/test/mf-driver.c'"' > $@
@echo 'void test() {' >> $@
- @cat $< >> $@
+ @echo '#include "'$<'"' >> $@
@echo '}' >> $@
+ @echo created $@
clean-local:
rm -f $(TESTS)
More information about the Gcc-patches
mailing list