Hello,in my calloc patch, I forgot to update the datastructure when replacing malloc with calloc.
Bootstrap+testsuite on x86_64-linux-gnu. 2014-06-25 Marc Glisse <marc.gli...@inria.fr> PR tree-optimization/57742 gcc/ * tree-ssa-strlen.c (handle_builtin_memset): Update strinfo after replacing the statement. gcc/testsuite/ * gcc.dg/tree-ssa/calloc-3.c: New file. -- Marc Glisse
Index: gcc/testsuite/gcc.dg/tree-ssa/calloc-3.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/calloc-3.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/calloc-3.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void*f(){ + char*p=__builtin_malloc(42); + __builtin_memset(p,0,42); + __builtin_memset(p,0,42); + return p; +}; + +/* { dg-final { scan-tree-dump-not "malloc" "optimized" } } */ +/* { dg-final { scan-tree-dump-times "calloc" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "memset" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c (revision 211968) +++ gcc/tree-ssa-strlen.c (working copy) @@ -1646,20 +1646,22 @@ handle_builtin_memset (gimple_stmt_itera enum built_in_function code1 = DECL_FUNCTION_CODE (callee1); tree size = gimple_call_arg (stmt2, 2); if (code1 == BUILT_IN_CALLOC) /* Not touching stmt1 */ ; else if (code1 == BUILT_IN_MALLOC && operand_equal_p (gimple_call_arg (stmt1, 0), size, 0)) { gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt1); update_gimple_call (&gsi1, builtin_decl_implicit (BUILT_IN_CALLOC), 2, size, build_one_cst (size_type_node)); + si1->length = build_int_cst (size_type_node, 0); + si1->stmt = gsi_stmt (gsi1); } else return true; tree lhs = gimple_call_lhs (stmt2); unlink_stmt_vdef (stmt2); if (lhs) { gimple assign = gimple_build_assign (lhs, ptr); gsi_replace (gsi, assign, false); }