https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126968
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:e33129b871c30276acfaed2b435ae5b505b73655 commit r17-5743-ge33129b871c30276acfaed2b435ae5b505b73655 Author: Jerry DeLisle <[email protected]> Date: Tue Oct 27 10:50:08 2026 -0400 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. Assisted-by: Claude Opus 5.5 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.
