ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
stack_budget.h
Go to the documentation of this file.
1#ifndef ESBMC_UTIL_STACK_BUDGET_H
2#define ESBMC_UTIL_STACK_BUDGET_H
3
4#include <cstddef>
5#include <cstdint>
6
23template <class Tag>
25{
26public:
28 {
29 if (depth++ == 0)
30 base = here();
31 }
32
34 {
35 if (--depth == 0)
36 base = 0;
37 }
38
41
43 std::ptrdiff_t bytes_used() const
44 {
45 // Direction is platform business, not ours -- take the magnitude.
46 const std::uintptr_t now = here();
47 return static_cast<std::ptrdiff_t>(now > base ? now - base : base - now);
48 }
49
50 bool exceeded(std::ptrdiff_t budget) const
51 {
52 return bytes_used() > budget;
53 }
54
55private:
56 /* An integer, not a pointer: the address is only ever differenced, never
57 * dereferenced, and storing it as a pointer to a local trips GCC's
58 * -Wdangling-pointer even though the guard clears it on the way out. */
59 std::uintptr_t here() const
60 {
61 return reinterpret_cast<std::uintptr_t>(&marker);
62 }
63
64 char marker;
65 static thread_local std::uintptr_t base;
66 static thread_local unsigned depth;
67};
68
69template <class Tag>
70thread_local std::uintptr_t stack_budget_guardt<Tag>::base = 0;
71template <class Tag>
72thread_local unsigned stack_budget_guardt<Tag>::depth = 0;
73
76constexpr std::ptrdiff_t default_stack_budget = 384L * 1024 * 1024;
77
78#endif
stack_budget_guardt(const stack_budget_guardt &)=delete
~stack_budget_guardt()
Definition stack_budget.h:33
stack_budget_guardt & operator=(const stack_budget_guardt &)=delete
std::ptrdiff_t bytes_used() const
Stack consumed since the outermost level.
Definition stack_budget.h:43
bool exceeded(std::ptrdiff_t budget) const
Definition stack_budget.h:50
stack_budget_guardt()
Definition stack_budget.h:27
constexpr std::ptrdiff_t default_stack_budget
Default ceiling for a walk.
Definition stack_budget.h:76