[PATCH] D86322: [flang] Fix bug accessing implicit variable in specification expression

Tim Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 16:37:32 PDT 2020


tskeith created this revision.
tskeith added reviewers: klausler, PeteSteinfeld, sscalpone.
tskeith added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
tskeith requested review of this revision.

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 object entities for each common block object during the
`PreSpecificationConstruct` pass and add the `InCommonBlock` flag to
identify them. 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86322

Files:
  flang/include/flang/Semantics/symbol.h
  flang/lib/Semantics/check-declarations.cpp
  flang/lib/Semantics/expression.cpp
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/block-data01.f90
  flang/test/Semantics/implicit11.f90
  flang/test/Semantics/offsets03.f90
  flang/test/Semantics/omp-symbol01.f90
  flang/test/Semantics/resolve42.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86322.286919.patch
Type: text/x-patch
Size: 22460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200820/556d932a/attachment.bin>


More information about the llvm-commits mailing list