[Bug tree-optimization/57742] memset(malloc(n),0,n) -> calloc(n,1)
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jun 25 08:09:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742
--- Comment #21 from Marc Glisse <glisse at gcc dot gnu.org> ---
I am testing the following:
--- tree-ssa-strlen.c (revision 211967)
+++ 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);
}
More information about the Gcc-bugs
mailing list