[all-commits] [llvm/llvm-project] 07de08: [flang] Detect circularly defined interfaces of pr...

Pete Steinfeld via All-commits all-commits at lists.llvm.org
Fri Feb 26 14:49:28 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 07de0846a5055015b55dc2b8faa2143f9902e549
      https://github.com/llvm/llvm-project/commit/07de0846a5055015b55dc2b8faa2143f9902e549
  Author: Peter Steinfeld <psteinfeld at nvidia.com>
  Date:   2021-02-26 (Fri, 26 Feb 2021)

  Changed paths:
    M flang/include/flang/Semantics/symbol.h
    M flang/lib/Evaluate/characteristics.cpp
    M flang/lib/Semantics/resolve-names.cpp
    M flang/test/Semantics/resolve102.f90

  Log Message:
  -----------
  [flang] Detect circularly defined interfaces of procedures

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 making SymbolSet be an ordered set, which does
not use the "<" operator.

I also added tests that will crash the compiler without this change.
And I fixed the formatting on an error message from a previous update.

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




More information about the All-commits mailing list