PR tree-optimization/50604
* builtins.c (fold_builtin_strcpy, fold_builtin_stpcpy,
fold_builtin_strncpy, fold_builtin_stxcpy_chk): Ensure
last argument to memcpy has size_type_node type instead of
ssizetype.
* tree-ssa-strlen.c (handle_builtin_memcpy): Use size_type_node
instead of TREE_TYPE (len) as type for newlen.
* gcc.dg/pr50604.c: New test.
From-SVN: r179508
2011-10-04 Jakub Jelinek <jakub@redhat.com>
2011-10-04 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/50604
+ * builtins.c (fold_builtin_strcpy, fold_builtin_stpcpy,
+ fold_builtin_strncpy, fold_builtin_stxcpy_chk): Ensure
+ last argument to memcpy has size_type_node type instead of
+ ssizetype.
+ * tree-ssa-strlen.c (handle_builtin_memcpy): Use size_type_node
+ instead of TREE_TYPE (len) as type for newlen.
+
PR tree-optimization/50522
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Don't test
TYPE_RESTRICT.
PR tree-optimization/50522
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Don't test
TYPE_RESTRICT.
- len = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
+ len = fold_convert_loc (loc, size_type_node, len);
+ len = size_binop_loc (loc, PLUS_EXPR, len, build_int_cst (size_type_node, 1));
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len));
}
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len));
}
if (!fn)
return NULL_TREE;
if (!fn)
return NULL_TREE;
- lenp1 = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
+ lenp1 = size_binop_loc (loc, PLUS_EXPR,
+ fold_convert_loc (loc, size_type_node, len),
+ build_int_cst (size_type_node, 1));
/* We use dest twice in building our expression. Save it from
multiple expansions. */
dest = builtin_save_expr (dest);
/* We use dest twice in building our expression. Save it from
multiple expansions. */
dest = builtin_save_expr (dest);
fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
if (!fn)
return NULL_TREE;
fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
if (!fn)
return NULL_TREE;
+
+ len = fold_convert_loc (loc, size_type_node, len);
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len));
}
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len));
}
if (!fn)
return NULL_TREE;
if (!fn)
return NULL_TREE;
- len = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
+ len = fold_convert_loc (loc, size_type_node, len);
+ len = size_binop_loc (loc, PLUS_EXPR, len,
+ build_int_cst (size_type_node, 1));
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 4,
dest, src, len, size));
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 4,
dest, src, len, size));
+2011-10-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/50604
+ * gcc.dg/pr50604.c: New test.
+
2011-10-04 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR tree-optimization/49662
2011-10-04 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR tree-optimization/49662
--- /dev/null
+/* PR tree-optimization/50604 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include "strlenopt.h"
+
+typedef char T;
+extern const T s[];
+
+void
+foo (T *x)
+{
+ char *r = malloc (strlen (x));
+ strcpy (r, s);
+ strcat (r, x);
+ strcat (r, "/");
+}
+
+const T s[] = "abcdefghijklmnopq";
if (si != NULL)
newlen = si->length;
else
if (si != NULL)
newlen = si->length;
else
- newlen = build_int_cst (TREE_TYPE (len), ~idx);
+ newlen = build_int_cst (size_type_node, ~idx);
oldlen = NULL_TREE;
if (olddsi != NULL)
{
oldlen = NULL_TREE;
if (olddsi != NULL)
{