diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-08-26 18:18:07 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-08-26 18:18:07 +0000 |
commit | 26a92d5852b2c6bf77efd26f6c0194c913f40285 (patch) | |
tree | ac752bec32ba60c72f8821d68345f8932005f713 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | cb2380c9fa4be10aaee30d0a04fd9b354b922802 (diff) | |
download | bcm5719-llvm-26a92d5852b2c6bf77efd26f6c0194c913f40285.tar.gz bcm5719-llvm-26a92d5852b2c6bf77efd26f6c0194c913f40285.zip |
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
llvm-svn: 369940
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index cbf519758ec..f0227d0501c 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -890,6 +890,11 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!"); assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!"); + // Mark this point as the bottom of the stack if we don't have somewhere + // better. We generally expect frontend actions to be invoked with (nearly) + // DesiredStackSpace available. + noteBottomOfStack(); + // FIXME: Take this as an argument, once all the APIs we used have moved to // taking it as an input instead of hard-coding llvm::errs. raw_ostream &OS = llvm::errs(); |