diff options
author | Andre Vehreschild <vehre@gcc.gnu.org> | 2024-07-17 12:30:52 +0200 |
---|---|---|
committer | Andre Vehreschild <vehre@gcc.gnu.org> | 2024-08-20 09:32:09 +0200 |
commit | 35f56012806432fd89bbae431950a8dc5f6729a3 (patch) | |
tree | 181c1a99cac8d233d4a424b1de931f1116b7d722 /gcc/fortran/trans-intrinsic.cc | |
parent | db2e9a2a46f64b037494e8300c46f2d90a9fa55c (diff) | |
download | gcc-35f56012806432fd89bbae431950a8dc5f6729a3.zip gcc-35f56012806432fd89bbae431950a8dc5f6729a3.tar.gz gcc-35f56012806432fd89bbae431950a8dc5f6729a3.tar.bz2 |
Fortran: Fix [Coarray] ICE in conv_caf_send, at fortran/trans-intrinsic.c:1950 [PR84246]
Fix ICE caused by converted expression already being pointer by checking
for its type. Lift rewrite to caf_send completely into resolve and
prevent more temporary arrays.
PR fortran/84246
gcc/fortran/ChangeLog:
* resolve.cc (caf_possible_reallocate): Detect arrays that may
be reallocated by caf_send.
(resolve_ordinary_assign): More reliably detect assignments
where a rewrite to caf_send is needed.
* trans-expr.cc (gfc_trans_assignment_1): Remove rewrite to
caf_send, because this is done by resolve now.
* trans-intrinsic.cc (conv_caf_send): Prevent unneeded temporary
arrays.
libgfortran/ChangeLog:
* caf/single.c (send_by_ref): Created array's lbound is now 1
and the offset set correctly.
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray_allocate_7.f08: Adapt to array being
allocate by caf_send.
Diffstat (limited to 'gcc/fortran/trans-intrinsic.cc')
-rw-r--r-- | gcc/fortran/trans-intrinsic.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index 8e1a2b0..fd2da46 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -1945,11 +1945,14 @@ conv_caf_send (gfc_code *code) { tree lhs_type = NULL_TREE; tree vec = null_pointer_node, rhs_vec = null_pointer_node; symbol_attribute lhs_caf_attr, rhs_caf_attr; + bool lhs_is_coindexed, rhs_is_coindexed; gcc_assert (flag_coarray == GFC_FCOARRAY_LIB); lhs_expr = code->ext.actual->expr; rhs_expr = code->ext.actual->next->expr; + lhs_is_coindexed = gfc_is_coindexed (lhs_expr); + rhs_is_coindexed = gfc_is_coindexed (rhs_expr); may_require_tmp = gfc_check_dependency (lhs_expr, rhs_expr, true) == 0 ? boolean_false_node : boolean_true_node; gfc_init_block (&block); @@ -1966,7 +1969,8 @@ conv_caf_send (gfc_code *code) { if (lhs_expr->ts.type == BT_CHARACTER && lhs_expr->ts.deferred) { lhs_se.expr = gfc_get_tree_for_caf_expr (lhs_expr); - lhs_se.expr = gfc_build_addr_expr (NULL_TREE, lhs_se.expr); + if (!POINTER_TYPE_P (TREE_TYPE (lhs_se.expr))) + lhs_se.expr = gfc_build_addr_expr (NULL_TREE, lhs_se.expr); } else { @@ -1999,7 +2003,7 @@ conv_caf_send (gfc_code *code) { { bool has_vector = gfc_has_vector_subscript (lhs_expr); - if (gfc_is_coindexed (lhs_expr) || !has_vector) + if (lhs_is_coindexed || !has_vector) { /* If has_vector, pass descriptor for whole array and the vector bounds separately. */ @@ -2030,7 +2034,7 @@ conv_caf_send (gfc_code *code) { *ar = ar2; } } - else + else if (rhs_is_coindexed) { /* Special casing for arr1 ([...]) = arr2[...], i.e. caf_get to indexed array expression. This is rewritten to: @@ -2122,13 +2126,12 @@ conv_caf_send (gfc_code *code) { /* Special case: RHS is a coarray but LHS is not; this code path avoids a temporary and a loop. */ - if (!gfc_is_coindexed (lhs_expr) + if (!lhs_is_coindexed && rhs_is_coindexed && (!lhs_caf_attr.codimension || !(lhs_expr->rank > 0 && (lhs_caf_attr.allocatable || lhs_caf_attr.pointer)))) { bool lhs_may_realloc = lhs_expr->rank > 0 && lhs_caf_attr.allocatable; - gcc_assert (gfc_is_coindexed (rhs_expr)); gfc_init_se (&rhs_se, NULL); if (lhs_expr->rank == 0 && lhs_caf_attr.allocatable) { @@ -2217,7 +2220,7 @@ conv_caf_send (gfc_code *code) { bool has_vector = false; tree tmp2; - if (gfc_is_coindexed (rhs_expr) && gfc_has_vector_subscript (rhs_expr)) + if (rhs_is_coindexed && gfc_has_vector_subscript (rhs_expr)) { has_vector = true; ar = gfc_find_array_ref (rhs_expr); @@ -2271,7 +2274,7 @@ conv_caf_send (gfc_code *code) { gfc_add_block_to_block (&block, &team_se.post); } - if (!gfc_is_coindexed (rhs_expr)) + if (!rhs_is_coindexed) { if (lhs_caf_attr.alloc_comp || lhs_caf_attr.pointer_comp) { |