[PATCH] D97201: [flang] Detect circularly defined interfaces of procedures

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 08:59:55 PST 2021


PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a subscriber: kristof.beyls.
PeteSteinfeld requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

It's possible to define a procedure whose interface depends on a procedure
which has an interface that depends on the original procedure.  Such a circular
definition was causing the compiler to fall into an infinite loop when
resolving the name of the second procedure.  It's also possible to create
circular dependency chains of more than two procedures.

I fixed this by adding the function HasCycle() to the class DeclarationVisitor
and calling it from DeclareProcEntity() to detect procedures with such
circularly defined interfaces.  I marked the associated symbols of such
procedures by calling SetError() on them.  When processing subsequent
procedures, I called HasError() before attempting to analyze their interfaces.
Unfortunately, this did not work.

With help from Tim, we determined that the SymbolSet used to track the
erroneous symbols was instantiated using a "<" operator which was defined using
the name of the procedure.  But the procedure name was being changed by a call
to ReplaceName() between the times that the calls to SetError() and HasError()
were made.  This caused HasError() to incorrectly report that a symbol was not
in the set of erroneous symbols.

I fixed this by changing the definition of the "<" operator used to instantiate
SymbolSet, which is defined in symbol.h.  This, in turn, caused the compiler to
change the order in which objects in a scope were allocated.  This, in turn,
caused the tests data05.f90 and typeinfo01.f90 to fail when comparing the size,
offsets, and order of symbols in a scope.  I assume that this change is
harmless.  I checked the new results of these tests to verify that the only
changes were as described.

I also added tests that will crash the compiler without this change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97201

Files:
  flang/include/flang/Semantics/symbol.h
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/data05.f90
  flang/test/Semantics/resolve102.f90
  flang/test/Semantics/typeinfo01.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97201.325462.patch
Type: text/x-patch
Size: 13591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210222/e4de39f6/attachment.bin>


More information about the llvm-commits mailing list