[all-commits] [llvm/llvm-project] b8bfe3: [flang] Fix bug accessing implicit variable in spe...

Tim Keith via All-commits all-commits at lists.llvm.org
Mon Aug 24 12:54:13 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: b8bfe3586eb892951b79eb70f8af758a318db861
      https://github.com/llvm/llvm-project/commit/b8bfe3586eb892951b79eb70f8af758a318db861
  Author: Tim Keith <tkeith at nvidia.com>
  Date:   2020-08-24 (Mon, 24 Aug 2020)

  Changed paths:
    M flang/include/flang/Parser/tools.h
    M flang/include/flang/Semantics/symbol.h
    M flang/include/flang/Semantics/tools.h
    M flang/lib/Semantics/check-declarations.cpp
    M flang/lib/Semantics/compute-offsets.cpp
    M flang/lib/Semantics/expression.cpp
    M flang/lib/Semantics/resolve-names.cpp
    M flang/lib/Semantics/tools.cpp
    M flang/test/Semantics/block-data01.f90
    A flang/test/Semantics/implicit11.f90
    M flang/test/Semantics/modfile21.f90
    M flang/test/Semantics/resolve42.f90

  Log Message:
  -----------
  [flang] Fix bug accessing implicit variable in specification expression

A specification expression can reference an implicitly declared variable
in the host procedure. Because we have to process specification parts
before execution parts, this may be the first time we encounter the
variable. We were assuming the variable was implicitly declared in the
scope where it was encountered, leading to an error because local
variables may not be referenced in specification expressions.

The fix is to tentatively create the implicit variable in the host
procedure because that is the only way the specification expression can
be valid. We mark it with the flag `ImplicitOrError` to indicate that
either it must be implicitly defined in the host (by being mentioned in
the execution part) or else its use turned out to be an error.
We need to apply the implicit type rules of the host, which requires
some changes to implicit typing.

Variables in common blocks are allowed to appear in specification expressions
(because they are not locals) but the common block definition may not appear
until after their use. To handle this we create common block symbols and object
entities for each common block object during the `PreSpecificationConstruct`
pass. This allows us to remove the corresponding code in the main visitor and
`commonBlockInfo_.curr`. The change in order of processing causes some
different error messages to be emitted.

Some cleanup is included with this change:
- In `ExpressionAnalyzer`, if an unresolved name is encountered but
  no error has been reported, emit an internal error.
- Change `ImplicitRulesVisitor` to hide the `ImplicitRules` object
  that implements it. Change the interface to pass in names rather
  than having to get the first character of the name.
- Change `DeclareObjectEntity` to have the `attrs` argument default
  to an empty set; that is the typical case.
- In `Pre(parser::SpecificationPart)` use "structured bindings" to
  give names to the pieces that make up a specification-part.
- Enhance `parser::Unwrap` to unwrap `Statement` and `UnlabeledStatement`
  and make use of that in PreSpecificationConstruct.

Differential Revision: https://reviews.llvm.org/D86322




More information about the All-commits mailing list