PS I forgot the Assisted-by: line in there. I have added it.
On 10/28/26 11:16 AM, Jerry DeLisle wrote:
See the following attached patch.
This was actually a nasty problem. It could only be seen if the testcase that
failed happened to be written in a certain way and only showed up with -m32.
I tested this patch on x86_64. The failure also reproduces with an arm-linux-
gnueabihf cross compiler (same 6 errors in associate_91); the patch fixes it
there as well..
OK for mainline?
Regards,
Jerry
---
[PATCH] fortran: [PR126968] Make inferred ASSOCIATE type guess
target-independent
The test associate_91.f90, added for PR126968, failed with -m32.
When an ASSOCIATE selector is a function that has not been parsed yet,
gfc_match_varspec guesses the type of the associate name from the first
component reference. Any accessible derived type with a component of
that name is a candidate, and the first candidate is used. The
candidates were collected by a pre-order walk of the symtree. The shape
of the symtree depends on how many symbols were inserted before, which
differs between targets. With -m32 the guess for associate_91 became a
type in which the component is a scalar integer, so the rest of the
reference, q%c1(4)%c2(:)%bar, could not be parsed.
Pick the first candidate in which the whole component chain exists, and
collect the candidates by an in-order walk so that the guess no longer
depends on the target.
With the guess now predictable, associate_93.f90 is changed so that both
of its blocks start from a wrong guess. This exposed a case that was
never exercised on x86_64: when the guessed component is a scalar
character, a following section such as t(2:3) is parsed as a substring.
When the real component is an array, turn the substring back into an
array section.
PR fortran/126968
gcc/fortran/ChangeLog:
* primary.cc (skip_ref_groups): New function.
(inferred_type_chain_ok): New function.
(gfc_match_varspec): Use it to choose among the candidate types of
an inferred-type associate name.
* resolve.cc (fixup_inferred_component_array_ref): Turn a substring
into an array section when the component is a rank-1 array.
* symbol.cc (find_derived_types): Walk the symtree in order.
gcc/testsuite/ChangeLog:
* gfortran.dg/associate_93.f90: Rename the guessed types so that
they are tried first.
* gfortran.dg/associate_97.f90: New test.
---