aboutsummaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/Stack.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:09 +0000
commit519fc96c475680de2cc49e7811dbbfadb912cbcc (patch)
tree310ca684459b7e9ae13c9a3b9abf308b3a634afe /include/clang/Basic/Stack.h
parent2298981669bf3bd63335a4be179bc0f96823a8f4 (diff)
downloadsrc-vendor/clang.tar.gz
src-vendor/clang.zip
Vendor import of stripped clang trunk r375505, the last commit beforevendor/clang/clang-trunk-r375505vendor/clang
the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/cfe/trunk@375505
Notes
Notes: svn path=/vendor/clang/dist/; revision=353942 svn path=/vendor/clang/clang-r375505/; revision=353943; tag=vendor/clang/clang-trunk-r375505
Diffstat (limited to 'include/clang/Basic/Stack.h')
-rw-r--r--include/clang/Basic/Stack.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/clang/Basic/Stack.h b/include/clang/Basic/Stack.h
index e0b04099de58..3418c3bad11b 100644
--- a/include/clang/Basic/Stack.h
+++ b/include/clang/Basic/Stack.h
@@ -16,11 +16,40 @@
#include <cstddef>
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Compiler.h"
+
namespace clang {
/// The amount of stack space that Clang would like to be provided with.
/// If less than this much is available, we may be unable to reach our
/// template instantiation depth limit and other similar limits.
constexpr size_t DesiredStackSize = 8 << 20;
+
+ /// Call this once on each thread, as soon after starting the thread as
+ /// feasible, to note the approximate address of the bottom of the stack.
+ void noteBottomOfStack();
+
+ /// Determine whether the stack is nearly exhausted.
+ bool isStackNearlyExhausted();
+
+ void runWithSufficientStackSpaceSlow(llvm::function_ref<void()> Diag,
+ llvm::function_ref<void()> Fn);
+
+ /// Run a given function on a stack with "sufficient" space. If stack space
+ /// is insufficient, calls Diag to emit a diagnostic before calling Fn.
+ inline void runWithSufficientStackSpace(llvm::function_ref<void()> Diag,
+ llvm::function_ref<void()> Fn) {
+#ifdef LLVM_ENABLE_THREADS
+ if (LLVM_UNLIKELY(isStackNearlyExhausted()))
+ runWithSufficientStackSpaceSlow(Diag, Fn);
+ else
+ Fn();
+#else
+ if (LLVM_UNLIKELY(isStackNearlyExhausted()))
+ Diag();
+ Fn();
+#endif
+ }
} // end namespace clang
#endif // LLVM_CLANG_BASIC_STACK_H