aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2005-02-13 01:43:58 -0500
committerJason Merrill <jason@gcc.gnu.org>2005-02-13 01:43:58 -0500
commit38116e3d1dfad4dc10da5863e1676e69b4682c54 (patch)
treec43953a2f4ab67d576c5e64bbca5f4aa01d20a3c /gcc/fold-const.c
parent6f49fdcc5efbe3d098c49b62c94646bc503b4d3d (diff)
downloadgcc-38116e3d1dfad4dc10da5863e1676e69b4682c54.zip
gcc-38116e3d1dfad4dc10da5863e1676e69b4682c54.tar.gz
gcc-38116e3d1dfad4dc10da5863e1676e69b4682c54.tar.bz2
re PR libmudflap/19319 (Mudflap produce many violations on simple, correct c++ program)
PR mudflap/19319 * gimplify.c (gimplify_modify_expr_rhs) [CALL_EXPR]: Make return slot explicit. PR c++/16405 * fold-const.c (fold_indirect_ref_1): Split out from... (build_fold_indirect_ref): Here. (fold_indirect_ref): New fn. * tree.h: Declare it. * gimplify.c (gimplify_compound_lval): Call fold_indirect_ref. (gimplify_modify_expr_rhs): Likewise. (gimplify_expr): Likewise. From-SVN: r94979
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 601f023..afe3afc 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11217,17 +11217,21 @@ build_fold_addr_expr (tree t)
return build_fold_addr_expr_with_type (t, build_pointer_type (TREE_TYPE (t)));
}
-/* Builds an expression for an indirection through T, simplifying some
- cases. */
+/* Given a pointer value T, return a simplified version of an indirection
+ through T, or NULL_TREE if no simplification is possible. */
-tree
-build_fold_indirect_ref (tree t)
+static tree
+fold_indirect_ref_1 (tree t)
{
tree type = TREE_TYPE (TREE_TYPE (t));
tree sub = t;
tree subtype;
STRIP_NOPS (sub);
+ subtype = TREE_TYPE (sub);
+ if (!POINTER_TYPE_P (subtype))
+ return NULL_TREE;
+
if (TREE_CODE (sub) == ADDR_EXPR)
{
tree op = TREE_OPERAND (sub, 0);
@@ -11242,7 +11246,6 @@ build_fold_indirect_ref (tree t)
}
/* *(foo *)fooarrptr => (*fooarrptr)[0] */
- subtype = TREE_TYPE (sub);
if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
&& lang_hooks.types_compatible_p (type, TREE_TYPE (TREE_TYPE (subtype))))
{
@@ -11250,7 +11253,34 @@ build_fold_indirect_ref (tree t)
return build4 (ARRAY_REF, type, sub, size_zero_node, NULL_TREE, NULL_TREE);
}
- return build1 (INDIRECT_REF, type, t);
+ return NULL_TREE;
+}
+
+/* Builds an expression for an indirection through T, simplifying some
+ cases. */
+
+tree
+build_fold_indirect_ref (tree t)
+{
+ tree sub = fold_indirect_ref_1 (t);
+
+ if (sub)
+ return sub;
+ else
+ return build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
+}
+
+/* Given an INDIRECT_REF T, return either T or a simplified version. */
+
+tree
+fold_indirect_ref (tree t)
+{
+ tree sub = fold_indirect_ref_1 (TREE_OPERAND (t, 0));
+
+ if (sub)
+ return sub;
+ else
+ return t;
}
/* Strip non-trapping, non-side-effecting tree nodes from an expression