Hi Paul!

Am 15.05.24 um 19:07 schrieb Paul Richard Thomas:
Hi All,

I have been around several circuits with a patch for this regression. I
posted one in Bugzilla but rejected it because it was not direct enough.
This one, however, is more to my liking and fixes another bug lurking in
the shadows.

The way in which select type has been implemented is a bit weird in that
the select type temporaries don't get their assoc set until resolution.
Therefore, if the selector is of inferred type, the namespace is tagged by
setting 'assoc_name_inferred'. This narrows down the range of select type
temporaries that are picked out by the chunk in primary.cc, thereby fixing
the problem.

I think that is a most reasonable approach.  I like it!

What I find hard to read is the logic in match.cc that sets
gfc_current_ns->assoc_name_inferred.  I wonder if reordering the
outer if-conditions and adding a comment might be a good thing:

@@ -6721,6 +6721,20 @@ gfc_match_select_type (void)
       goto cleanup;
     }

+  if (expr2 && expr2->expr_type == EXPR_VARIABLE
+      && expr2->symtree->n.sym->assoc)
+    {
+      if (expr2->symtree->n.sym->assoc->inferred_type)
+       gfc_current_ns->assoc_name_inferred = 1;
+      else if (expr2->symtree->n.sym->assoc->target
+              && expr2->symtree->n.sym->assoc->target->ts.type ==
BT_UNKNOWN)
+       gfc_current_ns->assoc_name_inferred = 1;
+    }
+  else if (!expr2
+          && expr1->symtree->n.sym->assoc
+          && expr1->symtree->n.sym->assoc->inferred_type)
+    gfc_current_ns->assoc_name_inferred = 1;

As the second part refers to the case there is only a selector
and no associate-name, i.e. the simple case, have it first?

Otherwise it looks very good.

The chunks in resolve.cc fix a problem found on the way, where invalid
array references, either cause an ICE or were silently absorbed.

OK for mainline and 14-branch?

Yes.

Thanks for the patch!

Harald


Paul

Fortran: Fix select type regression due to r14-9489 [PR114874]

2024-05-15  Paul Thomas  <pa...@gcc.gnu.org>

gcc/fortran
PR fortran/114874
* gfortran.h: Add 'assoc_name_inferred' to gfc_namespace.
* match.cc (gfc_match_select_type) : Set 'assoc_name_inferred'
in select type namespace if the selector has inferred type.
* primary.cc (gfc_match_varspec): If a select type temporary
is apparently scalar and '(' has been detected, check to see if
the current name space has 'assoc_name_inferred' set. If so,
set inferred_type.
* resolve.cc (resolve_variable): If the namespace of a select
type temporary is marked with 'assoc_name_inferred' call
gfc_fixup_inferred_type_refs to ensure references are OK.
(gfc_fixup_inferred_type_refs): Catch invalid array refs..

gcc/testsuite/
PR fortran/114874
* gfortran.dg/pr114874_1.f90: New test for valid code.
* gfortran.dg/pr114874_2.f90: New test for invalid code.


Reply via email to