Do array index calculations in gfc_array_index_type

It was recently noticed that for a few of the coarray intrinsics array
index calculations were done in integer_type_node instead of
gfc_array_index_type.  This patch fixes this.

Regtested on x86_64-pc-linux-gnu.

gcc/fortran/ChangeLog:

2018-09-23  Janne Blomqvist  <jb@gcc.gnu.org>

	* trans-expr.c (gfc_caf_get_image_index): Do array index
	calculations in gfc_array_index_type.
	* trans-intrinsic.c (conv_intrinsic_event_query): Likewise.
	* trans-stmt.c (gfc_trans_lock_unlock): Likewise.
	(gfc_trans_event_post_wait): Likewise.

gcc/testsuite/ChangeLog:

2018-09-23  Janne Blomqvist  <jb@gcc.gnu.org>

	* gfortran.dg/coarray_lib_alloc_4.f90: Fix scan patterns.
	* gfortran.dg/coarray_lock_7.f90: Likewise.

From-SVN: r264513
This commit is contained in:
Janne Blomqvist 2018-09-23 14:03:38 +03:00
parent ee7fb0588c
commit 0f97b81b03
7 changed files with 61 additions and 60 deletions

View File

@ -1,3 +1,11 @@
2018-09-23 Janne Blomqvist <jb@gcc.gnu.org>
* trans-expr.c (gfc_caf_get_image_index): Do array index
calculations in gfc_array_index_type.
* trans-intrinsic.c (conv_intrinsic_event_query): Likewise.
* trans-stmt.c (gfc_trans_lock_unlock): Likewise.
(gfc_trans_event_post_wait): Likewise.
2018-09-23 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/87395

View File

@ -2095,60 +2095,56 @@ gfc_caf_get_image_index (stmtblock_t *block, gfc_expr *e, tree desc)
integer_zero_node);
}
img_idx = integer_zero_node;
extent = integer_one_node;
img_idx = build_zero_cst (gfc_array_index_type);
extent = build_one_cst (gfc_array_index_type);
if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
for (i = ref->u.ar.dimen; i < ref->u.ar.dimen + ref->u.ar.codimen; i++)
{
gfc_init_se (&se, NULL);
gfc_conv_expr_type (&se, ref->u.ar.start[i], integer_type_node);
gfc_conv_expr_type (&se, ref->u.ar.start[i], gfc_array_index_type);
gfc_add_block_to_block (block, &se.pre);
lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[i]);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, se.expr,
fold_convert(integer_type_node, lbound));
tmp = fold_build2_loc (input_location, MULT_EXPR, integer_type_node,
TREE_TYPE (lbound), se.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
extent, tmp);
img_idx = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
img_idx, tmp);
img_idx = fold_build2_loc (input_location, PLUS_EXPR,
TREE_TYPE (tmp), img_idx, tmp);
if (i < ref->u.ar.dimen + ref->u.ar.codimen - 1)
{
ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
tmp = fold_convert (integer_type_node, tmp);
extent = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
}
}
else
for (i = ref->u.ar.dimen; i < ref->u.ar.dimen + ref->u.ar.codimen; i++)
{
gfc_init_se (&se, NULL);
gfc_conv_expr_type (&se, ref->u.ar.start[i], integer_type_node);
gfc_conv_expr_type (&se, ref->u.ar.start[i], gfc_array_index_type);
gfc_add_block_to_block (block, &se.pre);
lbound = GFC_TYPE_ARRAY_LBOUND (TREE_TYPE (desc), i);
lbound = fold_convert (integer_type_node, lbound);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, se.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR, integer_type_node,
TREE_TYPE (lbound), se.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
extent, tmp);
img_idx = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
img_idx = fold_build2_loc (input_location, PLUS_EXPR, TREE_TYPE (tmp),
img_idx, tmp);
if (i < ref->u.ar.dimen + ref->u.ar.codimen - 1)
{
ubound = GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (desc), i);
ubound = fold_convert (integer_type_node, ubound);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, ubound, lbound);
tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
tmp, integer_one_node);
TREE_TYPE (ubound), ubound, lbound);
tmp = fold_build2_loc (input_location, PLUS_EXPR, TREE_TYPE (tmp),
tmp, build_one_cst (TREE_TYPE (tmp)));
extent = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
}
}
img_idx = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
img_idx, integer_one_node);
return img_idx;
img_idx = fold_build2_loc (input_location, PLUS_EXPR, TREE_TYPE (img_idx),
img_idx, build_one_cst (TREE_TYPE (img_idx)));
return fold_convert (integer_type_node, img_idx);
}

View File

@ -10663,7 +10663,7 @@ conv_intrinsic_event_query (gfc_code *code)
if (flag_coarray == GFC_FCOARRAY_LIB)
{
tree tmp, token, image_index;
tree index = size_zero_node;
tree index = build_zero_cst (gfc_array_index_type);
if (event_expr->expr_type == EXPR_FUNCTION
&& event_expr->value.function.isym
@ -10716,29 +10716,25 @@ conv_intrinsic_event_query (gfc_code *code)
desc = argse.expr;
*ar = ar2;
extent = integer_one_node;
extent = build_one_cst (gfc_array_index_type);
for (i = 0; i < ar->dimen; i++)
{
gfc_init_se (&argse, NULL);
gfc_conv_expr_type (&argse, ar->start[i], integer_type_node);
gfc_conv_expr_type (&argse, ar->start[i], gfc_array_index_type);
gfc_add_block_to_block (&argse.pre, &argse.pre);
lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[i]);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, argse.expr,
fold_convert(integer_type_node, lbound));
TREE_TYPE (lbound), argse.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
index = fold_build2_loc (input_location, PLUS_EXPR,
gfc_array_index_type, index,
fold_convert (gfc_array_index_type,
tmp));
TREE_TYPE (tmp), index, tmp);
if (i < ar->dimen - 1)
{
ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
tmp = fold_convert (integer_type_node, tmp);
extent = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
}
}
}

View File

@ -841,7 +841,7 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op)
if (flag_coarray == GFC_FCOARRAY_LIB)
{
tree tmp, token, image_index, errmsg, errmsg_len;
tree index = size_zero_node;
tree index = build_zero_cst (gfc_array_index_type);
tree caf_decl = gfc_get_tree_for_caf_expr (code->expr1);
if (code->expr1->symtree->n.sym->ts.type != BT_DERIVED
@ -884,27 +884,25 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op)
desc = argse.expr;
*ar = ar2;
extent = integer_one_node;
extent = build_one_cst (gfc_array_index_type);
for (i = 0; i < ar->dimen; i++)
{
gfc_init_se (&argse, NULL);
gfc_conv_expr_type (&argse, ar->start[i], integer_type_node);
gfc_conv_expr_type (&argse, ar->start[i], gfc_array_index_type);
gfc_add_block_to_block (&argse.pre, &argse.pre);
lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[i]);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, argse.expr,
fold_convert(integer_type_node, lbound));
TREE_TYPE (lbound), argse.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
index = fold_build2_loc (input_location, PLUS_EXPR,
integer_type_node, index, tmp);
TREE_TYPE (tmp), index, tmp);
if (i < ar->dimen - 1)
{
ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
tmp = fold_convert (integer_type_node, tmp);
extent = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
}
}
}
@ -938,6 +936,7 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op)
lock_acquired = gfc_create_var (integer_type_node, "acquired");
}
index = fold_convert (size_type_node, index);
if (op == EXEC_LOCK)
tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_lock, 7,
token, index, image_index,
@ -1038,7 +1037,7 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op)
gfc_start_block (&se.pre);
tree tmp, token, image_index, errmsg, errmsg_len;
tree index = size_zero_node;
tree index = build_zero_cst (gfc_array_index_type);
tree caf_decl = gfc_get_tree_for_caf_expr (code->expr1);
if (code->expr1->symtree->n.sym->ts.type != BT_DERIVED
@ -1083,28 +1082,25 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op)
desc = argse.expr;
*ar = ar2;
extent = integer_one_node;
extent = build_one_cst (gfc_array_index_type);
for (i = 0; i < ar->dimen; i++)
{
gfc_init_se (&argse, NULL);
gfc_conv_expr_type (&argse, ar->start[i], integer_type_node);
gfc_conv_expr_type (&argse, ar->start[i], gfc_array_index_type);
gfc_add_block_to_block (&argse.pre, &argse.pre);
lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[i]);
tmp = fold_build2_loc (input_location, MINUS_EXPR,
integer_type_node, argse.expr,
fold_convert(integer_type_node, lbound));
TREE_TYPE (lbound), argse.expr, lbound);
tmp = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
index = fold_build2_loc (input_location, PLUS_EXPR,
gfc_array_index_type, index,
fold_convert (gfc_array_index_type, tmp));
TREE_TYPE (tmp), index, tmp);
if (i < ar->dimen - 1)
{
ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
tmp = fold_convert (integer_type_node, tmp);
extent = fold_build2_loc (input_location, MULT_EXPR,
integer_type_node, extent, tmp);
TREE_TYPE (tmp), extent, tmp);
}
}
}

View File

@ -1,3 +1,8 @@
2018-09-23 Janne Blomqvist <jb@gcc.gnu.org>
* gfortran.dg/coarray_lib_alloc_4.f90: Fix scan patterns.
* gfortran.dg/coarray_lock_7.f90: Likewise.
2018-09-23 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/87395

View File

@ -38,7 +38,7 @@ program test_caf_alloc
deallocate(xx)
end
! { dg-final { scan-tree-dump-times "_gfortran_caf_is_present \\(xx\\.token, 2 - \\(integer\\(kind=4\\)\\) xx\\.dim\\\[0\\\]\\.lbound, &caf_ref\\.\[0-9\]+\\)|_gfortran_caf_is_present \\(xx\\.token, 2 - xx\\.dim\\\[0\\\]\\.lbound, &caf_ref\\.\[0-9\]+\\)" 10 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_is_present \\(xx\\.token, \\(integer\\(kind=4\\)\\) \\(2 - xx\\.dim\\\[0\\\]\\.lbound\\), &caf_ref\\.\[0-9\]+\\)|_gfortran_caf_is_present \\(xx\\.token, 2 - xx\\.dim\\\[0\\\]\\.lbound, &caf_ref\\.\[0-9\]+\\)" 10 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 1, &xx\\.token, \\(void \\*\\) &xx, 0B, 0B, 0\\)" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 7" 2 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 8" 2 "original" } }

View File

@ -35,12 +35,12 @@ end
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., 0, 0, 0B, 0B, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., 0, 0, 0B, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\\[0\\\].lbound\\) \\+ \\(integer\\(kind=4\\)\\) \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\\[1\\\].lbound\\), 0, 0B, &ii, 0B, 0\\);|_gfortran_caf_lock \\(caf_token.1, \\(3 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, 0B, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., \\(2 - \\(integer\\(kind=4\\)\\) parm...dim\\\[0\\\].lbound\\) \\+ \\(integer\\(kind=4\\)\\) \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\\[1\\\].lbound\\), 0, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(caf_token.., \\(2 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., .*\\(\\(3 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\)\\), 0, 0B, &ii, 0B, 0\\);|_gfortran_caf_lock \\(caf_token.1, \\(3 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, 0B, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., .*\\(\\(2 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\)\\), 0, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(caf_token.., \\(2 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR <parm...dim\\\[0\\\].ubound - parm...dim\\\[0\\\].lbound, -1> \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(three.token, 0, 5 - \\(integer\\(kind=4\\)\\) three.dim\\\[0\\\].lbound, &acquired.\[0-9\]+, 0B, 0B, 0\\);|_gfortran_caf_lock \\(three.token, 0, 5 - three.dim\\\[0\\\].lbound, &acquired.\[0-9\]+, 0B, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(three.token, 0, 8 - \\(integer\\(kind=4\\)\\) three.dim\\\[0\\\].lbound, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(three.token, 0, 8 - three.dim\\\[0\\\].lbound, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(three.token, 0, \\(integer\\(kind=4\\)\\) \\(5 - three.dim\\\[0\\\].lbound\\), &acquired.\[0-9\]+, 0B, 0B, 0\\);|_gfortran_caf_lock \\(three.token, 0, 5 - three.dim\\\[0\\\].lbound, &acquired.\[0-9\]+, 0B, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(three.token, 0, \\(integer\\(kind=4\\)\\) \\(8 - three.dim\\\[0\\\].lbound\\), &ii, 0B, 0\\);|_gfortran_caf_unlock \\(three.token, 0, 8 - three.dim\\\[0\\\].lbound, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(four.token, 1 - \\(integer\\(kind=4\\)\\) four.dim\\\[0\\\].lbound, 7 - \\(integer\\(kind=4\\)\\) four.dim\\\[1\\\].lbound, &acquired.\[0-9\]+, &ii, 0B, 0\\);|_gfortran_caf_lock \\(four.token, 1 - four.dim\\\[0\\\].lbound, 7 - four.dim\\\[1\\\].lbound, &acquired.\[0-9\]+, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(four.token, 2 - \\(integer\\(kind=4\\)\\) four.dim\\\[0\\\].lbound, 8 - \\(integer\\(kind=4\\)\\) four.dim\\\[1\\\].lbound, 0B, 0B, 0\\);|_gfortran_caf_unlock \\(four.token, 2 - four.dim\\\[0\\\].lbound, 8 - four.dim\\\[1\\\].lbound, 0B, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(four.token, .*\\(1 - four.dim\\\[0\\\].lbound\\), \\(integer\\(kind=4\\)\\) \\(7 - four.dim\\\[1\\\].lbound\\), &acquired.\[0-9\]+, &ii, 0B, 0\\);|_gfortran_caf_lock \\(four.token, 1 - four.dim\\\[0\\\].lbound, 7 - four.dim\\\[1\\\].lbound, &acquired.\[0-9\]+, &ii, 0B, 0\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(four.token, .*\\(2 - four.dim\\\[0\\\].lbound\\), \\(integer\\(kind=4\\)\\) \\(8 - four.dim\\\[1\\\].lbound\\), 0B, 0B, 0\\);|_gfortran_caf_unlock \\(four.token, 2 - four.dim\\\[0\\\].lbound, 8 - four.dim\\\[1\\\].lbound, 0B, 0B, 0\\);" 1 "original" } }