[flang-commits] [PATCH] D142771: [flang] Avoid crashing from recursion on very tall expression parse trees

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 09:58:08 PST 2023


klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

In the parse tree visitation framework (Parser/parse-tree-visitor.h)   
and in the semantic analyzer for expressions (Semantics/expression.cpp)
avoid crashing due to stack size limitations by using an iterative
traversal algorithm rather than straightforward recursive tree walking.
The iterative approach is the obvious one of building a work queue and
using it to (in the case of the parse tree visitor) call the visitor  
object's Pre() and Post() routines on subexpressions in the same order
as they would have been called during a recursive traversal.

This change helps the compiler survive some artificial stress tests
and perhaps with future exposure to machine-generated source code.


https://reviews.llvm.org/D142771

Files:
  flang/include/flang/Parser/parse-tree-visitor.h
  flang/include/flang/Semantics/expression.h
  flang/lib/Semantics/expression.cpp
  flang/test/Evaluate/big-expr-tree.F90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142771.492832.patch
Type: text/x-patch
Size: 9103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/4eb0ba2a/attachment.bin>


More information about the flang-commits mailing list