This is an archive of the discontinued LLVM Phabricator instance.

[flang] Extension: reduced scope for some implied DO loop indices
ClosedPublic

Authored by klausler on Aug 23 2021, 3:49 PM.

Details

Summary

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.

Diff Detail

Event Timeline

klausler created this revision.Aug 23 2021, 3:49 PM
klausler requested review of this revision.Aug 23 2021, 3:49 PM
jeanPerier accepted this revision.Aug 24 2021, 2:34 AM
This revision is now accepted and ready to land.Aug 24 2021, 2:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2021, 9:34 AM