https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96255

--- Comment #15 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Steve,

In your second version of the patch which I have applie and have been testing,
the last hunk states:

@@ -12359,6 +12365,12 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns,
int forall_save)
       gcc_assert (nvar <= total_var);
     }

+  /* Need to walk the code and replace references to the index-name with
+     references to the shadow index-name.  */
+  if (shadow)
+    gfc_fatal_error ("An index-name shadows a variable from outer scope, "
+                    "which causes a wrong-code bug.");
+
   /* Resolve the FORALL body.  */
   gfc_resolve_forall_body (code, nvar, var_expr);


At this point, we are not walking the code and we do not trigger this error. I
am assuming this is the place where we must do the walk and set this shadow
flag.

If outside the loop, we declare a variable with the same name as the index
name, it seems this should be accepted. However, if we do not declare it
outside the loop and it is declared inside we should give an error if we try to
use it outside the loop when IMPLICIT NONE.

For example:

program looper
  implicit none

  !integer i

  do concurrent (integer(kind=4) :: i=1:10, j=1:9, k=2:7)
   print *, i, j, k
  end do

  print *, "All done!"

  print *, i, j, k

end program looper

Gives:
    ... snipped ...
           6           9           7
           7           9           7
           8           9           7
           9           9           7
          10           9           7
 All done!
  -751740621  2062093568           0

Notice that outside the loop the index variable are not defined but we do not
give an agnostic about not being implicitly declared.

Seeking clarification/opinion.

Reply via email to