Commit 80642376 by Jakub Jelinek Committed by Jakub Jelinek

re PR middle-end/50604 (verify_gimple failed: type mismatch in binary expression)

	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
parent c17d253c
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 PR tree-optimization/50522
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Don't test * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Don't test
TYPE_RESTRICT. TYPE_RESTRICT.
...@@ -8288,7 +8288,8 @@ fold_builtin_strcpy (location_t loc, tree fndecl, tree dest, tree src, tree len) ...@@ -8288,7 +8288,8 @@ fold_builtin_strcpy (location_t loc, tree fndecl, tree dest, tree src, tree len)
return NULL_TREE; 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)), return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len)); build_call_expr_loc (loc, fn, 3, dest, src, len));
} }
...@@ -8319,7 +8320,9 @@ fold_builtin_stpcpy (location_t loc, tree fndecl, tree dest, tree src) ...@@ -8319,7 +8320,9 @@ fold_builtin_stpcpy (location_t loc, tree fndecl, tree dest, tree src)
if (!fn) if (!fn)
return NULL_TREE; 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 /* We use dest twice in building our expression. Save it from
multiple expansions. */ multiple expansions. */
dest = builtin_save_expr (dest); dest = builtin_save_expr (dest);
...@@ -8375,6 +8378,8 @@ fold_builtin_strncpy (location_t loc, tree fndecl, tree dest, ...@@ -8375,6 +8378,8 @@ fold_builtin_strncpy (location_t loc, tree fndecl, tree dest,
fn = implicit_built_in_decls[BUILT_IN_MEMCPY]; fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
if (!fn) if (!fn)
return NULL_TREE; return NULL_TREE;
len = fold_convert_loc (loc, size_type_node, len);
return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)), return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 3, dest, src, len)); build_call_expr_loc (loc, fn, 3, dest, src, len));
} }
...@@ -12127,7 +12132,9 @@ fold_builtin_stxcpy_chk (location_t loc, tree fndecl, tree dest, ...@@ -12127,7 +12132,9 @@ fold_builtin_stxcpy_chk (location_t loc, tree fndecl, tree dest,
if (!fn) if (!fn)
return NULL_TREE; 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)), return fold_convert_loc (loc, TREE_TYPE (TREE_TYPE (fndecl)),
build_call_expr_loc (loc, fn, 4, build_call_expr_loc (loc, fn, 4,
dest, src, len, size)); 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> 2011-10-04 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR tree-optimization/49662 PR tree-optimization/49662
......
/* 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";
...@@ -1297,7 +1297,7 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1297,7 +1297,7 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
if (si != NULL) if (si != NULL)
newlen = si->length; newlen = si->length;
else else
newlen = build_int_cst (TREE_TYPE (len), ~idx); newlen = build_int_cst (size_type_node, ~idx);
oldlen = NULL_TREE; oldlen = NULL_TREE;
if (olddsi != NULL) if (olddsi != NULL)
{ {
......
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