This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix ASSOCIATE statement name resolution
ClosedPublic

Authored by klausler on Jan 19 2021, 5:12 PM.

Details

Summary

F18 Clause 19.4p9 says:

The associate names of an ASSOCIATE construct have the scope of the
block.

Clause 11.3.1p1 says the ASSOCIATE statement is not itself in the block:

R1102 associate-construct is:  associate-stmt block end-associate-stmt

Associate statement associations are currently fully processed from left
to right, incorrectly interposing associating entities earlier in the
list on same-named entities in the host scope.

1  program p
2    logical :: a = .false.
3    real :: b = 9.73
4    associate (b => a, a => b)
5      print*, a, b
6    end associate
7    print*, a, b
8  end

Associating names 'a' and 'b' at line 4 in this code are now both
aliased to logical host entity 'a' at line 2. This happens because the
reference to 'b' in the second association incorrectly resolves 'b' to
the entity in line 4 (already associated to 'a' at line 2), rather than
the 'b' at line 3. With bridge code to process these associations,
f18 output is:

F F
F 9.73

It should be:

9.73 F
F 9.73

To fix this, names in right-hand side selector variables/expressions
must all be resolved before any left-hand side entities are resolved.
This is done by maintaining a stack of lists of associations, rather
than a stack of associations. Each ASSOCIATE statement's list of
assocations is then visited once for right-hand side processing, and
once for left-hand side processing.

Note that other construct associations do not have this problem.
SELECT RANK and SELECT TYPE each have a single assocation, not a list.
Constraint C1113 prohibits the right-hand side of a CHANGE TEAM
association from referencing any left-hand side entity.

Diff Detail

Event Timeline

klausler created this revision.Jan 19 2021, 5:12 PM
klausler requested review of this revision.Jan 19 2021, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2021, 5:12 PM
tskeith accepted this revision.Jan 19 2021, 5:29 PM
This revision is now accepted and ready to land.Jan 19 2021, 5:29 PM
This revision was automatically updated to reflect the committed changes.