This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
strlen: update datastructure when replacing malloc with calloc
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 25 Jun 2014 13:16:38 +0200 (CEST)
- Subject: strlen: update datastructure when replacing malloc with calloc
- Authentication-results: sourceware.org; auth=none
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.glisse@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);
}