fortran: [PR103474] Fix ICEs for the cobounds of a subobject of a coarray

F2018:5.4.7(5) makes a subobject of a coarray a coarray with the same
codimensions, unless it is reached through a cosubscript, an image
selector, or an allocatable or pointer component selector.  Querying the
cobounds of such a subobject, as in LCOBOUND (X%A), reached three places
that were not prepared for it, and a coarray whose declaration had already
been rejected reached a fourth.

	PR fortran/103474

gcc/fortran/ChangeLog:

	* simplify.cc (simplify_cobound): Take the array spec from the
	base symbol, using its class data for a CLASS coarray, so that a
	subobject of a coarray finds the codimensions.  Return NULL for a
	symbol already flagged as erroneous and in place of the two
	gcc_unreachable calls reached on invalid code.
	* resolve.cc (gfc_expression_rank): Track the reference carrying
	the codimensions and take the corank from it rather than from the
	last array reference.  Clear it at an allocatable or pointer
	component selector, which ends the coarray.
	* trans-intrinsic.cc (strip_subobject_of_coarray): New function.
	Return a copy of the expression cut back to the reference carrying
	the codimensions.
	(conv_intrinsic_cobound, trans_this_image, trans_image_index): Use
	it, so that the descriptor queried for the cobounds is that of the
	coarray and not that of a component of it.

gcc/testsuite/ChangeLog:

	* gfortran.dg/coarray_52.f90: New test.
	* gfortran.dg/coarray/cobounds_subobject_1.f90: New test.
5 files changed