This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix some type issues in the middle-end
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 12 Jul 2007 12:29:27 +0200 (CEST)
- Subject: [PATCH] Fix some type issues in the middle-end
This fixes mismatched types generated in the middle-end that were
exposed by bootstrapping & testing ada. With this patch all default
languages and ada bootstrap with the type-checker.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
mainline.
Richard.
2007-07-12 Richard Guenther <rguenther@suse.de>
* gimplify.c (gimplify_conversion): Make sure that the result
from maybe_fold_offset_to_reference is trivially convertible
to the desired type before doing the simplification.
(gimplify_expr): Likewise.
* fold-const.c (fold_binary): Use the correct types for
building the simplified expression.
Index: gcc/gimplify.c
===================================================================
*** gcc.orig/gimplify.c 2007-07-12 11:35:21.000000000 +0200
--- gcc/gimplify.c 2007-07-12 11:39:05.000000000 +0200
*************** gimplify_conversion (tree *expr_p)
*** 1648,1654 ****
&& (tem = maybe_fold_offset_to_reference
(TREE_OPERAND (*expr_p, 0),
integer_zero_node, TREE_TYPE (TREE_TYPE (*expr_p)))))
! *expr_p = build_fold_addr_expr_with_type (tem, TREE_TYPE (*expr_p));
/* If we still have a conversion at the toplevel,
then canonicalize some constructs. */
--- 1645,1655 ----
&& (tem = maybe_fold_offset_to_reference
(TREE_OPERAND (*expr_p, 0),
integer_zero_node, TREE_TYPE (TREE_TYPE (*expr_p)))))
! {
! tree ptr_type = build_pointer_type (TREE_TYPE (tem));
! if (useless_type_conversion_p (TREE_TYPE (*expr_p), ptr_type))
! *expr_p = build_fold_addr_expr_with_type (tem, ptr_type);
! }
/* If we still have a conversion at the toplevel,
then canonicalize some constructs. */
*************** gimplify_expr (tree *expr_p, tree *pre_p
*** 5987,5995 ****
(TREE_OPERAND (*expr_p, 0), TREE_OPERAND (*expr_p, 1),
TREE_TYPE (TREE_TYPE (*expr_p)))))
{
! *expr_p = build_fold_addr_expr_with_type (tmp,
! TREE_TYPE (*expr_p));
! break;
}
/* Convert (void *)&a + 4 into (void *)&a[1]. */
if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR
--- 5976,5987 ----
(TREE_OPERAND (*expr_p, 0), TREE_OPERAND (*expr_p, 1),
TREE_TYPE (TREE_TYPE (*expr_p)))))
{
! tree ptr_type = build_pointer_type (TREE_TYPE (tmp));
! if (useless_type_conversion_p (TREE_TYPE (*expr_p), ptr_type))
! {
! *expr_p = build_fold_addr_expr_with_type (tmp, ptr_type);
! break;
! }
}
/* Convert (void *)&a + 4 into (void *)&a[1]. */
if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR
Index: gcc/fold-const.c
===================================================================
*** gcc.orig/fold-const.c 2007-07-12 11:35:21.000000000 +0200
--- gcc/fold-const.c 2007-07-12 11:39:06.000000000 +0200
*************** fold_binary (enum tree_code code, tree t
*** 10271,10277 ****
if (integer_zerop (arg1))
return non_lvalue (fold_convert (type, arg0));
if (integer_all_onesp (arg1))
! return fold_build1 (BIT_NOT_EXPR, type, arg0);
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand (type, integer_zero_node, arg0);
--- 10271,10277 ----
if (integer_zerop (arg1))
return non_lvalue (fold_convert (type, arg0));
if (integer_all_onesp (arg1))
! return fold_build1 (BIT_NOT_EXPR, type, op0);
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand (type, integer_zero_node, arg0);
*************** fold_binary (enum tree_code code, tree t
*** 10865,10871 ****
"when distributing negation across "
"division"),
WARN_STRICT_OVERFLOW_MISC);
! return fold_build2 (code, type, TREE_OPERAND (arg0, 0),
negate_expr (arg1));
}
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
--- 10865,10872 ----
"when distributing negation across "
"division"),
WARN_STRICT_OVERFLOW_MISC);
! return fold_build2 (code, type,
! fold_convert (type, TREE_OPERAND (arg0, 0)),
negate_expr (arg1));
}
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))