aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-ccp.c
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2010-09-07 17:50:22 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2010-09-07 15:50:22 +0000
commit9c4ce18d030434d47e6ad6b68caa4f630bc6df72 (patch)
treeca9a334cc242b08b21557c11f3aa17f41987eec5 /gcc/tree-ssa-ccp.c
parentd341a5d09057127a50c916b8708d4aa7d1f74ec8 (diff)
downloadgcc-9c4ce18d030434d47e6ad6b68caa4f630bc6df72.zip
gcc-9c4ce18d030434d47e6ad6b68caa4f630bc6df72.tar.gz
gcc-9c4ce18d030434d47e6ad6b68caa4f630bc6df72.tar.bz2
tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound in string access folding.
* tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound in string access folding. From-SVN: r163956
Diffstat (limited to 'gcc/tree-ssa-ccp.c')
-rw-r--r--gcc/tree-ssa-ccp.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index fc3f158..7341477 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -1398,17 +1398,30 @@ fold_const_aggregate_ref (tree t)
}
/* Fold read from constant string. */
- if (TREE_CODE (ctor) == STRING_CST)
+ if (TREE_CODE (ctor) == STRING_CST
+ && TREE_CODE (idx) == INTEGER_CST)
{
+ tree low_bound = array_ref_low_bound (t);
+ double_int low_bound_cst;
+ double_int index_cst;
+ double_int length_cst;
+ bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
+
+ if (TREE_CODE (low_bound) != INTEGER_CST)
+ return NULL_TREE;
+ low_bound_cst = tree_to_double_int (low_bound);
+ index_cst = tree_to_double_int (idx);
+ length_cst = uhwi_to_double_int (TREE_STRING_LENGTH (ctor));
+ index_cst = double_int_sub (index_cst, low_bound_cst);
if ((TYPE_MODE (TREE_TYPE (t))
== TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
&& (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
== MODE_INT)
&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == 1
- && compare_tree_int (idx, TREE_STRING_LENGTH (ctor)) < 0)
+ && double_int_cmp (index_cst, length_cst, signed_p) < 0)
return build_int_cst_type (TREE_TYPE (t),
(TREE_STRING_POINTER (ctor)
- [TREE_INT_CST_LOW (idx)]));
+ [double_int_to_uhwi (index_cst)]));
return NULL_TREE;
}