llvm-project/flang/lib
peter klausler ff3b51b054 [flang] Fix ASSOCIATE statement name resolution
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.

Differential Revision: https://reviews.llvm.org/D95010
2021-01-20 11:18:27 -08:00
..
Common [flang] Use the Flang cmake-functions to add targets. 2020-04-16 15:51:30 +01:00
Decimal [flang] Readability improvement in binary->decimal conversion 2020-10-01 15:49:27 -07:00
Evaluate [flang] Refine WhyNotModifiable() 2021-01-19 11:44:51 -08:00
Frontend [flang][driver] Move isFixedFormSuffix and isFreeFormSuffix to flangFrontend 2021-01-19 17:47:40 +00:00
FrontendTool [flang][driver] Move isFixedFormSuffix and isFreeFormSuffix to flangFrontend 2021-01-19 17:47:40 +00:00
Lower [flang][directive] Get rid of flangClassValue in TableGen 2021-01-19 10:28:46 -05:00
Optimizer [mlir] Remove the MutableDictionaryAttr class 2020-12-17 17:18:42 -08:00
Parser [flang][directive] Get rid of flangClassValue in TableGen 2021-01-19 10:28:46 -05:00
Semantics [flang] Fix ASSOCIATE statement name resolution 2021-01-20 11:18:27 -08:00
CMakeLists.txt [flang][driver] Add the new flang compiler and frontend drivers 2020-09-11 10:55:54 +01:00