]> granicus.if.org Git - clang/commit
Improve behavior in the case of stack exhaustion.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 26 Aug 2019 18:18:07 +0000 (18:18 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 26 Aug 2019 18:18:07 +0000 (18:18 +0000)
commitc3225a63e4764815f15310efd32aa8c97b46d6e0
treeae5407d5444713f818007c5436fe3488ccb9b6a9
parent2116900d5c2aef64b09edd88f1fe895a30731ce8
Improve behavior in the case of stack exhaustion.

Summary:
Clang performs various recursive operations (such as template instantiation),
and may use non-trivial amounts of stack space in each recursive step (for
instance, due to recursive AST walks). While we try to keep the stack space
used by such steps to a minimum and we have explicit limits on the number of
such steps we perform, it's impractical to guarantee that we won't blow out the
stack on deeply recursive template instantiations on complex ASTs, even with
only a moderately high instantiation depth limit.

The user experience in these cases is generally terrible: we crash with
no hint of what went wrong. Under this patch, we attempt to do better:

 * Detect when the stack is nearly exhausted, and produce a warning with a
   nice template instantiation backtrace, telling the user that we might
   run slowly or crash.

 * For cases where we're forced to trigger recursive template
   instantiation in arbitrarily-deeply-nested contexts, check whether
   we're nearly out of stack space and allocate a new stack (by spawning
   a new thread) after producing the warning.

Reviewers: rnk, aaron.ballman

Subscribers: mgorny, cfe-commits

Tags: #clang

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369940 91177308-0d34-0410-b5e6-96231b3b80d8
21 files changed:
include/clang/Basic/DiagnosticCommonKinds.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/Stack.h
include/clang/Sema/Sema.h
lib/Basic/CMakeLists.txt
lib/Basic/Stack.cpp [new file with mode: 0644]
lib/Frontend/CompilerInstance.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateDeduction.cpp
lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Sema/SemaType.cpp
test/CMakeLists.txt
test/SemaTemplate/stack-exhaustion.cpp [new file with mode: 0644]
test/lit.cfg.py
test/lit.site.cfg.py.in
tools/driver/driver.cpp