[PATCH] D102259: [flang] Limit the depth of expressions that the compiler will handle
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 11 10:44:08 PDT 2021
PeteSteinfeld created this revision.
Herald added a reviewer: sscalpone.
PeteSteinfeld requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The compiler analyzes expressions recusively. Large expressions consume large
amounts of stack space. Very large expressions can cause the compiler to
overflow the stack, which results in a seg fault.
I fixed this by imposing a limit of 1000 for the depth of the expression tree
analyzed by the compiler. Upon reaching this limit, the compiler will emit a
message, unwind from the analysis of that expression, and proceed with the rest
of the compilation.
The limit of 1000 is a little arbitrary. I experimentally verified that the
compiler cannot handle a limit of 5000, and 1000 seems big enough.
I added a test that will produce a seg fault without this change. It also
contains an expression with 1000 operations that gets constant folded. This
demonstrates that, if we can analyze an expression, we can fold it. I also
included two cases where we create array constructors of many more elements
than the expression limit to verify that we can handle large array
constructors.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102259
Files:
flang/include/flang/Semantics/expression.h
flang/lib/Semantics/expression.cpp
flang/test/Semantics/big-expr.f90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102259.344476.patch
Type: text/x-patch
Size: 18873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210511/2a2f2b83/attachment.bin>
More information about the llvm-commits
mailing list