return fold_convert (type, expr);
}
+ if (TREE_CODE (expr) == INTEGER_CST)
+ return int_const_convert (type, expr,
+ type == sizetype || type == bitsizetype
+ ? -1 : !POINTER_TYPE_P (etype));
+
/* ... fall through ... */
case ENUMERAL_TYPE:
MINUS_EXPR,
arg1, arg0)));
}
-\f
-/* A subroutine of fold_convert_const handling conversions of an
- INTEGER_CST to another integer type. */
-static tree
-fold_convert_const_int_from_int (tree type, const_tree arg1)
+/* Convert integer constant ARG1 to TYPE, which is an integral or offset
+ or pointer type. */
+
+tree
+int_const_convert (tree type, const_tree arg1, int overflowable)
{
/* Given an integer constant, make new constant with new type,
appropriately sign-extended or truncated. Use widest_int
unsigned prec = MAX (TYPE_PRECISION (arg1_type), TYPE_PRECISION (type));
return force_fit_type (type, wide_int::from (wi::to_wide (arg1), prec,
TYPE_SIGN (arg1_type)),
- !POINTER_TYPE_P (TREE_TYPE (arg1)),
+ overflowable,
TREE_OVERFLOW (arg1));
}
|| TREE_CODE (type) == OFFSET_TYPE)
{
if (TREE_CODE (arg1) == INTEGER_CST)
- return fold_convert_const_int_from_int (type, arg1);
+ return int_const_convert (type, arg1, !POINTER_TYPE_P (arg_type));
else if (TREE_CODE (arg1) == REAL_CST)
return fold_convert_const_int_from_real (code, type, arg1);
else if (TREE_CODE (arg1) == FIXED_CST)
const_tree, const_tree, signop,
wi::overflow_type *);
extern tree int_const_binop (enum tree_code, const_tree, const_tree, int = 1);
+extern tree int_const_convert (tree, const_tree, int = 1);
#define build_fold_addr_expr(T)\
build_fold_addr_expr_loc (UNKNOWN_LOCATION, (T))
extern tree build_fold_addr_expr_loc (location_t, tree);
--- /dev/null
+-- { dg-do compile }
+
+with System;
+
+procedure Object_Overflow6 is
+
+ type Address is range 0 .. System.Memory_Size;
+
+ type Arr is array (Address) of Character;
+
+ A : Arr; -- { dg-warning "Storage_Error" }
+
+begin
+ A(1) := 'a';
+end;