From: Richard Kenner Date: Fri, 18 Nov 2005 13:07:06 +0000 (+0000) Subject: fold-const.c (build_range_check): Use proper type for subtraction when merging lower... X-Git-Tag: releases/gcc-4.1.0~717 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=438090c3723d1d050bbc31a891e86db520bbd9f1;p=thirdparty%2Fgcc.git fold-const.c (build_range_check): Use proper type for subtraction when merging lower bound. * fold-const.c (build_range_check): Use proper type for subtraction when merging lower bound. From-SVN: r107178 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9a0a77cb00ef..ad2c25a44c95 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-11-18 Richard Kenner + + * fold-const.c (build_range_check): Use proper type for subtraction + when merging lower bound. + 2005-11-18 Zdenek Dvorak PR rtl-optimization/24497 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 343cfae69037..abaac755e3b3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4062,10 +4062,22 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) } if (value != 0 && ! TREE_OVERFLOW (value)) - return build_range_check (type, - fold_build2 (MINUS_EXPR, etype, exp, low), - 1, fold_convert (etype, integer_zero_node), - value); + { + /* There is no requirement that LOW be within the range of ETYPE + if the latter is a subtype. It must, however, be within the base + type of ETYPE. So be sure we do the subtraction in that type. */ + if (INTEGRAL_TYPE_P (etype) && TREE_TYPE (etype)) + { + etype = TREE_TYPE (etype); + exp = fold_convert (etype, exp); + low = fold_convert (etype, low); + value = fold_convert (etype, value); + } + + return build_range_check (type, + fold_build2 (MINUS_EXPR, etype, exp, low), + 1, build_int_cst (etype, 0), value); + } return 0; }