Re: [Ping, Fortran, Patch, PR85510, v2] Fix coarray token in associate not linking

2024-08-12 Thread Andre Vehreschild
Hi Jerry,

thanks for the review. Commited as gcc-15-2882-g8d8db21eb72.

Thanks again and regards,
Andre

On Fri, 9 Aug 2024 10:35:26 -0700
Jerry Delisle  wrote:

> Ok and thanks.
>
> On Fri, Aug 9, 2024, 7:33 AM Andre Vehreschild  wrote:
>
> > Ping!
> >
> > And the last ping in the series. I have a "bigger" patch in the queue and
> > want
> > the pending ones done beforehand.
> >
> > Regtested ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline?
> >
> > - Andre
> >
> > On Mon, 22 Jul 2024 16:35:28 +0200
> > Andre Vehreschild  wrote:
> >
> > > Hi all, hi Paul,
> > >
> > > you asked me to have a look at PR85510 (which the associate meta bug is
> > > blocked by). I have come up with the cause. The symbol of the coarray is
> > > deemed to be host_associated and therefore the caf_token is not created
> > in
> > > the correct scope. I am not familiar with host-association, so my
> > solution
> > > may be wrong. The essence of my patch is to ensure, that the namespace
> > the
> > > symbol is in is not caused by an associate command. I hope this is the
> > way to
> > > go.
> > >
> > > Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline?
> > >
> > > Regards,
> > >   Andre
> > > --
> > > Andre Vehreschild * Email: vehre ad gmx dot de
> >
> >
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de
> >


--
Andre Vehreschild * Email: vehre ad gmx dot de


[Fortran, Patch, PR110033, v1] Fix associate for coarrays

2024-08-12 Thread Andre Vehreschild
Hi all,

the attached two patches fix ASSOCIATE for coarrays, i.e. that a coarray
associated to a variable is also a coarray in the block of the ASSOCIATE
command. The patch has two parts:

1. pr110033p1_1.patch: Adds a corank member to the gfc_expr structure. I
decided to add it here and keep track of the corank of an expression, because
calling gfc_get_corank was getting to expensive with the associate patch. This
patch also improves the usage of coarrays in select type/rank constructs.

2. pr110033p2_1.patch: The changes and testcase for PR 110033. In essence the
coarray is not detected correctly on the expression to associate to and
therefore not propagated correctly into the block of the ASSOCIATE command. The
patch adds correct treatment for propagating the coarray token into the block,
too.

The costs of tracking the corank along side to the rank of an expression are
about 30 seconds real user time (i.e. time's "real" row) on a rather old Intel
i7-5775C@3.3GHz  with 24G RAM that was used for work during the test. If need be
I can tuned that more.

Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline?

Regards,
Andre
--
Andre Vehreschild * Email: vehre ad gmx dot de
From 7b7f2bad87e1c10b2addc54b1e6746cb56de0c78 Mon Sep 17 00:00:00 2001
From: Andre Vehreschild 
Date: Fri, 9 Aug 2024 12:47:18 +0200
Subject: [PATCH 1/2] [Fortran] Add corank to gfc_expr.

Compute the corank of an expression along side to the regular rank.
This safe costly calls to gfc_get_corank (), which consecutively has
been removed.  In some locations the code needed some adaption to model
the difference between expr.corank and gfc_get_corank correctly.  The
latter always returned the codimension of the expression and not its
current corank, i.e. the resolution of all indezes.

This commit is preparatory to fixing PR fortran/110033 and may contain
parts of that fix already.

gcc/fortran/ChangeLog:

	* arith.cc (reduce_unary): Use expr.corank.
	(reduce_binary_ac): Same.
	(reduce_binary_ca): Same.
	(reduce_binary_aa): Same.
	* array.cc (gfc_match_array_ref): Same.
	* check.cc (dim_corank_check): Same.
	(gfc_check_move_alloc): Same.
	(gfc_check_image_index): Same.
	* class.cc (gfc_add_class_array_ref): Same.
	(finalize_component): Same.
	* data.cc (gfc_assign_data_value): Same.
	* decl.cc (match_clist_expr): Same.
	(add_init_expr_to_sym): Same.
	* expr.cc (simplify_intrinsic_op): Same.
	(simplify_parameter_variable): Same.
	(gfc_check_assign_symbol): Same.
	(gfc_get_variable_expr): Same.
	(gfc_add_full_array_ref): Same.
	(gfc_lval_expr_from_sym): Same.
	(gfc_get_corank): Removed.
	* frontend-passes.cc (callback_reduction): Use expr.corank.
	(create_var): Same.
	(combine_array_constructor): Same.
	(optimize_minmaxloc): Same.
	* gfortran.h (gfc_get_corank): Add corank to gfc_expr.
	* intrinsic.cc (gfc_get_intrinsic_function_symbol): Use
	expr.corank.
	(gfc_convert_type_warn): Same.
	(gfc_convert_chartype): Same.
	* iresolve.cc (resolve_bound): Same.
	(gfc_resolve_cshift): Same.
	(gfc_resolve_eoshift): Same.
	(gfc_resolve_logical): Same.
	(gfc_resolve_matmul): Same.
	* match.cc (copy_ts_from_selector_to_associate): Same.
	* matchexp.cc (gfc_get_parentheses): Same.
	* parse.cc (parse_associate): Same.
	* primary.cc (gfc_match_rvalue): Same.
	* resolve.cc (resolve_structure_cons): Same.
	(resolve_actual_arglist): Same.
	(resolve_elemental_actual): Same.
	(resolve_generic_f0): Same.
	(resolve_unknown_f): Same.
	(resolve_operator): Same.
	(gfc_expression_rank): Same and set dimen_type for coarray to
	default.
	(gfc_op_rank_conformable): Use expr.corank.
	(add_caf_get_intrinsic): Same.
	(resolve_variable): Same.
	(gfc_fixup_inferred_type_refs): Same.
	(check_host_association): Same.
	(resolve_compcall): Same.
	(resolve_expr_ppc): Same.
	(resolve_assoc_var): Same.
	(fixup_array_ref): Same.
	(resolve_select_type): Same.
	(add_comp_ref): Same.
	(get_temp_from_expr): Same.
	(resolve_fl_var_and_proc): Same.
	(resolve_symbol): Same.
	* symbol.cc (gfc_is_associate_pointer): Same.
	* trans-array.cc (walk_coarray): Same.
	(gfc_conv_expr_descriptor): Same.
	(gfc_walk_array_ref): Same.
	* trans-array.h (gfc_walk_array_ref): Same.
	* trans-expr.cc (gfc_get_ultimate_alloc_ptr_comps_caf_token):
	Same.
	* trans-intrinsic.cc (trans_this_image): Same.
	(trans_image_index): Same.
	(conv_intrinsic_cobound): Same.
	(gfc_walk_intrinsic_function): Same.
	(conv_intrinsic_move_alloc): Same.
	* trans-stmt.cc (gfc_trans_lock_unlock): Same.
	(trans_associate_var): Same and adapt to slightly different
	behaviour of expr.corank and gfc_get_corank.
	(gfc_trans_allocate): Same.
	* trans.cc (gfc_add_finalizer_call): Same.
---
 gcc/fortran/arith.cc   |   4 +
 gcc/fortran/array.cc   |  16 ++-
 gcc/fortran/check.cc   |  18 +--
 gcc/fortran/class.cc   |   3 +
 gcc/fortran/data.cc|   1 +
 gcc/fortran/decl.cc|   2 +
 gcc/fortran/expr.cc|  51 +++
 gcc/fortran/frontend-passes.cc |   5 +
 gcc/fo