This is an archive of the discontinued LLVM Phabricator instance.

[flang] Don't reference non-invariant symbols in shape expressions
ClosedPublic

Authored by klausler on Nov 5 2021, 12:31 PM.

Details

Summary

When an array's shape involves references to symbols that are not
invariant in a scope -- the classic example being a dummy array
with an explicit shape involving other dummy arguments -- the
compiler was creating shape expressions that referenced those
symbols. This might be valid if those symbols are somehow
captured and copied at each entry point to a subprogram, and
the copies referenced in the shapes instead, but that's not
the case.

This patch introduces a new expression predicate IsScopeInvariantExpr(),
which defines a class of expressions that contains constant expressions
(in the sense that the standard uses that term) as well as references
to items that may be safely accessed in a context-free way throughout
their scopes. This includes dummy arguments that are INTENT(IN)
and not VALUE, descriptor inquiries into descriptors that cannot
change, and bare LEN type parameters within the definitions of
derived types. The new predicate is then used in shape analysis
to winnow out results that would have otherwise been contextual.

Diff Detail

Event Timeline

klausler created this revision.Nov 5 2021, 12:31 PM
klausler requested review of this revision.Nov 5 2021, 12:31 PM
jeanPerier accepted this revision.Nov 8 2021, 12:55 AM

Looks great

This revision is now accepted and ready to land.Nov 8 2021, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2021, 12:49 PM