diff options
author | Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> | 2018-01-03 16:07:32 +0000 |
---|---|---|
committer | Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org> | 2018-01-03 16:07:32 +0000 |
commit | 65f2d1ee1c20860e238750099b88e394ee30a770 (patch) | |
tree | 39a1b922636b131e994dcc24e956ad6826434e59 /gcc/tree-ssa-strlen.c | |
parent | ce4734988f9ee022fbe5195f85ea04e7372a9eda (diff) | |
download | gcc-65f2d1ee1c20860e238750099b88e394ee30a770.zip gcc-65f2d1ee1c20860e238750099b88e394ee30a770.tar.gz gcc-65f2d1ee1c20860e238750099b88e394ee30a770.tar.bz2 |
re PR tree-optimization/83501 (strlen(a) not folded after strcpy(a, "..."))
2018-01-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
PR tree-optimization/83501
* tree-ssa-strlen.c (get_string_cst): New.
(handle_char_store): Call get_string_cst.
testsuite/
* gcc.dg/tree-ssa/pr83501.c: New test.
From-SVN: r256180
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 8f7020c..f4fd69f 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -2772,6 +2772,21 @@ handle_pointer_plus (gimple_stmt_iterator *gsi) } } +/* Check if RHS is string_cst possibly wrapped by mem_ref. */ +static tree +get_string_cst (tree rhs) +{ + if (TREE_CODE (rhs) == MEM_REF + && integer_zerop (TREE_OPERAND (rhs, 1))) + { + rhs = TREE_OPERAND (rhs, 0); + if (TREE_CODE (rhs) == ADDR_EXPR) + rhs = TREE_OPERAND (rhs, 0); + } + + return (TREE_CODE (rhs) == STRING_CST) ? rhs : NULL_TREE; +} + /* Handle a single character store. */ static bool @@ -2927,11 +2942,11 @@ handle_char_store (gimple_stmt_iterator *gsi) } } else if (idx == 0 - && TREE_CODE (gimple_assign_rhs1 (stmt)) == STRING_CST + && (rhs = get_string_cst (gimple_assign_rhs1 (stmt))) && ssaname == NULL_TREE && TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE) { - size_t l = strlen (TREE_STRING_POINTER (gimple_assign_rhs1 (stmt))); + size_t l = strlen (TREE_STRING_POINTER (rhs)); HOST_WIDE_INT a = int_size_in_bytes (TREE_TYPE (lhs)); if (a > 0 && (unsigned HOST_WIDE_INT) a > l) { |