Commit 10dcf221 by Kazu Hirata Committed by Kazu Hirata

re PR middle-end/21024 (fold generates a comparison of two operands whose types do not match)

	PR middle-end/21024
	* builtins.c (expand_builtin_strcat): Convert the result of
	strlen to the right type.
	* fold-const.c (fold_binary) <PLUS_EXPR>: Use fold_convert to
	avoid creating type mismatches.
	<GE_EXPR>: Pass op0 and op1 to fold_build2 to avoid creating
	type mismatches.

From-SVN: r98244
parent eee0d85e
2005-04-17 Kazu Hirata <kazu@cs.umass.edu>
PR middle-end/21024
* builtins.c (expand_builtin_strcat): Convert the result of
strlen to the right type.
* fold-const.c (fold_binary) <PLUS_EXPR>: Use fold_convert to
avoid creating type mismatches.
<GE_EXPR>: Pass op0 and op1 to fold_build2 to avoid creating
type mismatches.
2005-04-16 Richard Henderson <rth@redhat.com> 2005-04-16 Richard Henderson <rth@redhat.com>
PR target/21051 PR target/21051
......
...@@ -3810,7 +3810,8 @@ expand_builtin_strcat (tree arglist, tree type, rtx target, enum machine_mode mo ...@@ -3810,7 +3810,8 @@ expand_builtin_strcat (tree arglist, tree type, rtx target, enum machine_mode mo
fold (build_function_call_expr (strlen_fn, fold (build_function_call_expr (strlen_fn,
build_tree_list (NULL_TREE, build_tree_list (NULL_TREE,
dst))); dst)));
/* Create (dst + strlen (dst)). */ /* Create (dst + (cast) strlen (dst)). */
newdst = fold_convert (TREE_TYPE (dst), newdst);
newdst = fold (build2 (PLUS_EXPR, TREE_TYPE (dst), dst, newdst)); newdst = fold (build2 (PLUS_EXPR, TREE_TYPE (dst), dst, newdst));
/* Prepend the new dst argument. */ /* Prepend the new dst argument. */
......
...@@ -7250,11 +7250,15 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) ...@@ -7250,11 +7250,15 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
case PLUS_EXPR: case PLUS_EXPR:
/* A + (-B) -> A - B */ /* A + (-B) -> A - B */
if (TREE_CODE (arg1) == NEGATE_EXPR) if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2 (MINUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)); return fold_build2 (MINUS_EXPR, type,
fold_convert (type, arg0),
fold_convert (type, TREE_OPERAND (arg1, 0)));
/* (-A) + B -> B - A */ /* (-A) + B -> B - A */
if (TREE_CODE (arg0) == NEGATE_EXPR if (TREE_CODE (arg0) == NEGATE_EXPR
&& reorder_operands_p (TREE_OPERAND (arg0, 0), arg1)) && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
return fold_build2 (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)); return fold_build2 (MINUS_EXPR, type,
fold_convert (type, arg1),
fold_convert (type, TREE_OPERAND (arg0, 0)));
/* Convert ~A + 1 to -A. */ /* Convert ~A + 1 to -A. */
if (INTEGRAL_TYPE_P (type) if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (arg0) == BIT_NOT_EXPR && TREE_CODE (arg0) == BIT_NOT_EXPR
...@@ -7390,7 +7394,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) ...@@ -7390,7 +7394,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
fold_build2 (PLUS_EXPR, type, fold_build2 (PLUS_EXPR, type,
fold_convert (type, alt0), fold_convert (type, alt0),
fold_convert (type, alt1)), fold_convert (type, alt1)),
same); fold_convert (type, same));
} }
/* Try replacing &a[i1] + c * i2 with &a[i1 + i2], if c is step /* Try replacing &a[i1] + c * i2 with &a[i1 + i2], if c is step
...@@ -8786,7 +8790,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) ...@@ -8786,7 +8790,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
case GE_EXPR: case GE_EXPR:
/* If one arg is a real or integer constant, put it last. */ /* If one arg is a real or integer constant, put it last. */
if (tree_swap_operands_p (arg0, arg1, true)) if (tree_swap_operands_p (arg0, arg1, true))
return fold_build2 (swap_tree_comparison (code), type, arg1, arg0); return fold_build2 (swap_tree_comparison (code), type, op1, op0);
/* If this is an equality comparison of the address of a non-weak /* If this is an equality comparison of the address of a non-weak
object against zero, then we know the result. */ object against zero, then we know the result. */
......
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