Commit 7c57b2f1 by Francois-Xavier Coudert Committed by François-Xavier Coudert

re PR fortran/32046 (wrong code with -O2 for gfortran.dg/interface_12.f90 & result_in_spec_1.f90)

	PR fortran/32046
	* trans-expr.c (gfc_trans_zero_assign): Convert the result of
	TYPE_SIZE_UNIT into a signed type.
	(gfc_trans_array_copy):  Likewise.
	(gfc_trans_array_constructor_copy): Likewise.
	* trans-array.c (gfc_trans_create_temp_array): Likewise.
	(gfc_grow_array): Likewise.
	(gfc_array_init_size): Likewise.
	(gfc_duplicate_allocatable): Likewise.
	* trans-stmt.c (allocate_temp_for_forall_nest_1): Likewise.

From-SVN: r124985
parent 6d0ceb76
2007-05-23 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/32046
* trans-expr.c (gfc_trans_zero_assign): Convert the result of
TYPE_SIZE_UNIT into a signed type.
(gfc_trans_array_copy): Likewise.
(gfc_trans_array_constructor_copy): Likewise.
* trans-array.c (gfc_trans_create_temp_array): Likewise.
(gfc_grow_array): Likewise.
(gfc_array_init_size): Likewise.
(gfc_duplicate_allocatable): Likewise.
* trans-stmt.c (allocate_temp_for_forall_nest_1): Likewise.
2007-05-22 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2007-05-22 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/18923 PR fortran/18923
......
...@@ -687,7 +687,8 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, ...@@ -687,7 +687,8 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post,
nelem = size; nelem = size;
size = fold_build2 (MULT_EXPR, gfc_array_index_type, size, size = fold_build2 (MULT_EXPR, gfc_array_index_type, size,
TYPE_SIZE_UNIT (gfc_get_element_type (type))); fold_convert (gfc_array_index_type,
TYPE_SIZE_UNIT (gfc_get_element_type (type))));
} }
else else
{ {
...@@ -838,7 +839,8 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra) ...@@ -838,7 +839,8 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
/* Calculate the new array size. */ /* Calculate the new array size. */
size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc))); size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
tmp = build2 (PLUS_EXPR, gfc_array_index_type, ubound, gfc_index_one_node); tmp = build2 (PLUS_EXPR, gfc_array_index_type, ubound, gfc_index_one_node);
arg1 = build2 (MULT_EXPR, gfc_array_index_type, tmp, size); arg1 = build2 (MULT_EXPR, gfc_array_index_type, tmp,
fold_convert (gfc_array_index_type, size));
/* Pick the appropriate realloc function. */ /* Pick the appropriate realloc function. */
if (gfc_index_integer_kind == 4) if (gfc_index_integer_kind == 4)
...@@ -3427,7 +3429,8 @@ gfc_array_init_size (tree descriptor, int rank, tree * poffset, ...@@ -3427,7 +3429,8 @@ gfc_array_init_size (tree descriptor, int rank, tree * poffset,
/* The stride is the number of elements in the array, so multiply by the /* The stride is the number of elements in the array, so multiply by the
size of an element to get the total size. */ size of an element to get the total size. */
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type)); tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
size = fold_build2 (MULT_EXPR, gfc_array_index_type, stride, tmp); size = fold_build2 (MULT_EXPR, gfc_array_index_type, stride,
fold_convert (gfc_array_index_type, tmp));
if (poffset != NULL) if (poffset != NULL)
{ {
...@@ -4960,7 +4963,8 @@ gfc_duplicate_allocatable(tree dest, tree src, tree type, int rank) ...@@ -4960,7 +4963,8 @@ gfc_duplicate_allocatable(tree dest, tree src, tree type, int rank)
nelems = get_full_array_size (&block, src, rank); nelems = get_full_array_size (&block, src, rank);
size = fold_build2 (MULT_EXPR, gfc_array_index_type, nelems, size = fold_build2 (MULT_EXPR, gfc_array_index_type, nelems,
TYPE_SIZE_UNIT (gfc_get_element_type (type))); fold_convert (gfc_array_index_type,
TYPE_SIZE_UNIT (gfc_get_element_type (type))));
/* Allocate memory to the destination. */ /* Allocate memory to the destination. */
tmp = gfc_call_malloc (&block, TREE_TYPE (gfc_conv_descriptor_data_get (src)), tmp = gfc_call_malloc (&block, TREE_TYPE (gfc_conv_descriptor_data_get (src)),
......
...@@ -3619,8 +3619,9 @@ gfc_trans_zero_assign (gfc_expr * expr) ...@@ -3619,8 +3619,9 @@ gfc_trans_zero_assign (gfc_expr * expr)
if (!len || TREE_CODE (len) != INTEGER_CST) if (!len || TREE_CODE (len) != INTEGER_CST)
return NULL_TREE; return NULL_TREE;
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
len = fold_build2 (MULT_EXPR, gfc_array_index_type, len, len = fold_build2 (MULT_EXPR, gfc_array_index_type, len,
TYPE_SIZE_UNIT (gfc_get_element_type (type))); fold_convert (gfc_array_index_type, tmp));
/* Convert arguments to the correct types. */ /* Convert arguments to the correct types. */
if (!POINTER_TYPE_P (TREE_TYPE (dest))) if (!POINTER_TYPE_P (TREE_TYPE (dest)))
...@@ -3673,6 +3674,7 @@ gfc_trans_array_copy (gfc_expr * expr1, gfc_expr * expr2) ...@@ -3673,6 +3674,7 @@ gfc_trans_array_copy (gfc_expr * expr1, gfc_expr * expr2)
{ {
tree dst, dlen, dtype; tree dst, dlen, dtype;
tree src, slen, stype; tree src, slen, stype;
tree tmp;
dst = gfc_get_symbol_decl (expr1->symtree->n.sym); dst = gfc_get_symbol_decl (expr1->symtree->n.sym);
src = gfc_get_symbol_decl (expr2->symtree->n.sym); src = gfc_get_symbol_decl (expr2->symtree->n.sym);
...@@ -3691,14 +3693,16 @@ gfc_trans_array_copy (gfc_expr * expr1, gfc_expr * expr2) ...@@ -3691,14 +3693,16 @@ gfc_trans_array_copy (gfc_expr * expr1, gfc_expr * expr2)
dlen = GFC_TYPE_ARRAY_SIZE (dtype); dlen = GFC_TYPE_ARRAY_SIZE (dtype);
if (!dlen || TREE_CODE (dlen) != INTEGER_CST) if (!dlen || TREE_CODE (dlen) != INTEGER_CST)
return NULL_TREE; return NULL_TREE;
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (dtype));
dlen = fold_build2 (MULT_EXPR, gfc_array_index_type, dlen, dlen = fold_build2 (MULT_EXPR, gfc_array_index_type, dlen,
TYPE_SIZE_UNIT (gfc_get_element_type (dtype))); fold_convert (gfc_array_index_type, tmp));
slen = GFC_TYPE_ARRAY_SIZE (stype); slen = GFC_TYPE_ARRAY_SIZE (stype);
if (!slen || TREE_CODE (slen) != INTEGER_CST) if (!slen || TREE_CODE (slen) != INTEGER_CST)
return NULL_TREE; return NULL_TREE;
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (stype));
slen = fold_build2 (MULT_EXPR, gfc_array_index_type, slen, slen = fold_build2 (MULT_EXPR, gfc_array_index_type, slen,
TYPE_SIZE_UNIT (gfc_get_element_type (stype))); fold_convert (gfc_array_index_type, tmp));
/* Sanity check that they are the same. This should always be /* Sanity check that they are the same. This should always be
the case, as we should already have checked for conformance. */ the case, as we should already have checked for conformance. */
...@@ -3720,6 +3724,7 @@ gfc_trans_array_constructor_copy (gfc_expr * expr1, gfc_expr * expr2) ...@@ -3720,6 +3724,7 @@ gfc_trans_array_constructor_copy (gfc_expr * expr1, gfc_expr * expr2)
tree dst, dtype; tree dst, dtype;
tree src, stype; tree src, stype;
tree len; tree len;
tree tmp;
nelem = gfc_constant_array_constructor_p (expr2->value.constructor); nelem = gfc_constant_array_constructor_p (expr2->value.constructor);
if (nelem == 0) if (nelem == 0)
...@@ -3741,8 +3746,9 @@ gfc_trans_array_constructor_copy (gfc_expr * expr1, gfc_expr * expr2) ...@@ -3741,8 +3746,9 @@ gfc_trans_array_constructor_copy (gfc_expr * expr1, gfc_expr * expr2)
if (compare_tree_int (len, nelem) != 0) if (compare_tree_int (len, nelem) != 0)
return NULL_TREE; return NULL_TREE;
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (dtype));
len = fold_build2 (MULT_EXPR, gfc_array_index_type, len, len = fold_build2 (MULT_EXPR, gfc_array_index_type, len,
TYPE_SIZE_UNIT (gfc_get_element_type (dtype))); fold_convert (gfc_array_index_type, tmp));
stype = gfc_typenode_for_spec (&expr2->ts); stype = gfc_typenode_for_spec (&expr2->ts);
src = gfc_build_constant_array_constructor (expr2, stype); src = gfc_build_constant_array_constructor (expr2, stype);
......
...@@ -2086,7 +2086,7 @@ allocate_temp_for_forall_nest_1 (tree type, tree size, stmtblock_t * block, ...@@ -2086,7 +2086,7 @@ allocate_temp_for_forall_nest_1 (tree type, tree size, stmtblock_t * block,
tree unit; tree unit;
tree tmp; tree tmp;
unit = TYPE_SIZE_UNIT (type); unit = fold_convert (gfc_array_index_type, TYPE_SIZE_UNIT (type));
if (!integer_onep (unit)) if (!integer_onep (unit))
bytesize = fold_build2 (MULT_EXPR, gfc_array_index_type, size, unit); bytesize = fold_build2 (MULT_EXPR, gfc_array_index_type, size, unit);
else else
......
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