aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c7
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3b88179..5ce9dc6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2012-03-06 Richard Guenther <rguenther@suse.de>
+ * fold-const.c (build_fold_addr_expr_with_type_loc): Fold
+ MEM_REF with constant pointer operand.
+
+2012-03-06 Richard Guenther <rguenther@suse.de>
+
PR middle-end/52493
* tree-ssa-alias.c (ptr_derefs_may_alias_p): Robustify.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6492f11..0f80675 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7626,8 +7626,13 @@ build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype)
t = build1_loc (loc, NOP_EXPR, ptrtype, t);
}
else if (TREE_CODE (t) == MEM_REF
- && integer_zerop (TREE_OPERAND (t, 1)))
+ && integer_zerop (TREE_OPERAND (t, 1)))
return TREE_OPERAND (t, 0);
+ else if (TREE_CODE (t) == MEM_REF
+ && TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST)
+ return fold_binary (POINTER_PLUS_EXPR, ptrtype,
+ TREE_OPERAND (t, 0),
+ convert_to_ptrofftype (TREE_OPERAND (t, 1)));
else if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
{
t = build_fold_addr_expr_loc (loc, TREE_OPERAND (t, 0));