t = fold_convert (itype, s0);
t = fold_build2 (MULT_EXPR, itype, t, step);
if (POINTER_TYPE_P (type))
- t = fold_build_pointer_plus (n1, t);
+ {
+ t = fold_build_pointer_plus (n1, t);
+ if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+ t = fold_convert (signed_type_for (type), t);
+ }
else
t = fold_build2 (PLUS_EXPR, type, t, n1);
t = fold_convert (TREE_TYPE (startvar), t);
t = fold_convert (itype, e0);
t = fold_build2 (MULT_EXPR, itype, t, step);
if (POINTER_TYPE_P (type))
- t = fold_build_pointer_plus (n1, t);
+ {
+ t = fold_build_pointer_plus (n1, t);
+ if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+ t = fold_convert (signed_type_for (type), t);
+ }
else
t = fold_build2 (PLUS_EXPR, type, t, n1);
t = fold_convert (TREE_TYPE (startvar), t);
t = fold_convert (itype, s0);
t = fold_build2 (MULT_EXPR, itype, t, step);
if (POINTER_TYPE_P (type))
- t = fold_build_pointer_plus (n1, t);
+ {
+ t = fold_build_pointer_plus (n1, t);
+ if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+ t = fold_convert (signed_type_for (type), t);
+ }
else
t = fold_build2 (PLUS_EXPR, type, t, n1);
t = fold_convert (TREE_TYPE (startvar), t);
t = fold_convert (itype, e0);
t = fold_build2 (MULT_EXPR, itype, t, step);
if (POINTER_TYPE_P (type))
- t = fold_build_pointer_plus (n1, t);
+ {
+ t = fold_build_pointer_plus (n1, t);
+ if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+ t = fold_convert (signed_type_for (type), t);
+ }
else
t = fold_build2 (PLUS_EXPR, type, t, n1);
t = fold_convert (TREE_TYPE (startvar), t);