[flang-commits] [PATCH] D95010: [flang] Fix ASSOCIATE statement name resolution
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Jan 19 17:12:59 PST 2021
klausler created this revision.
klausler added a reviewer: tskeith.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
F18 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95010
Files:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/resolve100.f90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95010.317729.patch
Type: text/x-patch
Size: 5590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210120/2b914df8/attachment-0001.bin>
More information about the flang-commits
mailing list