Commit 198fe1bf by Jakub Jelinek Committed by Jakub Jelinek

re PR tree-optimization/57230 (tree-ssa-strlen incorrectly optimizes a strlen to 0)

	PR tree-optimization/57230
	* tree-ssa-strlen.c (handle_char_store): Record length for
	array store from STRING_CST.

	* gcc.dg/strlenopt-24.c: New test.

From-SVN: r198815
parent 3a60f32b
2013-05-13 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/57230
* tree-ssa-strlen.c (handle_char_store): Record length for
array store from STRING_CST.
PR tree-optimization/57230
* tree-ssa-strlen.c (handle_char_store): Add missing integer_zerop
check.
......
2013-05-13 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/57230
* gcc.dg/strlenopt-24.c: New test.
PR tree-optimization/57230
* gcc.dg/strlenopt-23.c: New test.
2013-05-12 Oleg Endo <olegendo@gcc.gnu.org>
......
/* PR tree-optimization/57230 */
/* { dg-do run } */
/* { dg-options "-O2 -fdump-tree-strlen" } */
#include "strlenopt.h"
int
main ()
{
char p[] = "hello world";
if (strlen (p) != 11)
abort ();
return 0;
}
/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } *
/* { dg-final { cleanup-tree-dump "strlen" } } */
......@@ -1740,6 +1740,25 @@ handle_char_store (gimple_stmt_iterator *gsi)
if (si != NULL)
si->writable = true;
}
else if (idx == 0
&& TREE_CODE (gimple_assign_rhs1 (stmt)) == STRING_CST
&& ssaname == NULL_TREE
&& TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE)
{
size_t l = strlen (TREE_STRING_POINTER (gimple_assign_rhs1 (stmt)));
HOST_WIDE_INT a = int_size_in_bytes (TREE_TYPE (lhs));
if (a > 0 && (unsigned HOST_WIDE_INT) a > l)
{
int idx = new_addr_stridx (lhs);
if (idx != 0)
{
si = new_strinfo (build_fold_addr_expr (lhs), idx,
build_int_cst (size_type_node, l));
set_strinfo (idx, si);
si->dont_invalidate = true;
}
}
}
if (si != NULL && initializer_zerop (gimple_assign_rhs1 (stmt)))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment