[flang-commits] [PATCH] D108595: [flang] Extension: reduced scope for some implied DO loop indices

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Aug 23 15:49:05 PDT 2021


klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
klausler requested review of this revision.

The index of an implied DO loop in a DATA statement or array
constructor is defined by Fortran 2018 to have scope over its
implied DO loop.  This definition is unfortunate, because it
requires the implied DO loop's bounds expressions to be in the
scope of the index variable.  Consequently, in code like

  integer, parameter :: j = 5
  real, save :: a(5) = [(j, j=1, j)]

the upper bound of the loop is a reference to the index variable,
not the parameter in the enclosing scope.

This patch limits the scope of the index variable to the "body"
of the implied DO loop as one would naturally expect, with a warning.
I would have preferred to make this a hard error, but most Fortran
compilers treat this case as f18 now does.  If the standard
were to be fixed, the warning could be made optional.


https://reviews.llvm.org/D108595

Files:
  flang/docs/Extensions.md
  flang/lib/Semantics/expression.cpp
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/array-constr-values.f90
  flang/test/Semantics/data11.f90
  flang/test/Semantics/modfile25.f90
  flang/test/Semantics/modfile26.f90
  flang/test/Semantics/resolve106.f90
  flang/test/Semantics/resolve30.f90
  flang/test/Semantics/symbol05.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108595.368230.patch
Type: text/x-patch
Size: 16845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210823/b606ad05/attachment-0001.bin>


More information about the flang-commits mailing list