File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ InterpState::~InterpState() {
5959void InterpState::cleanup () {
6060 // As a last resort, make sure all pointers still pointing to a dead block
6161 // don't point to it anymore.
62- Alloc.cleanup ();
62+ if (Alloc)
63+ Alloc->cleanup ();
6364}
6465
6566Frame *InterpState::getCurrentFrame () {
@@ -103,10 +104,13 @@ void InterpState::deallocate(Block *B) {
103104}
104105
105106bool InterpState::maybeDiagnoseDanglingAllocations () {
106- bool NoAllocationsLeft = !Alloc.hasAllocations ();
107+ if (!Alloc)
108+ return true ;
109+
110+ bool NoAllocationsLeft = !Alloc->hasAllocations ();
107111
108112 if (!checkingPotentialConstantExpression ()) {
109- for (const auto &[Source, Site] : Alloc. allocation_sites ()) {
113+ for (const auto &[Source, Site] : Alloc-> allocation_sites ()) {
110114 assert (!Site.empty ());
111115
112116 CCEDiag (Source->getExprLoc (), diag::note_constexpr_memory_leak)
Original file line number Diff line number Diff line change @@ -118,7 +118,13 @@ class InterpState final : public State, public SourceMapper {
118118
119119 void setEvalLocation (SourceLocation SL) { this ->EvalLocation = SL; }
120120
121- DynamicAllocator &getAllocator () { return Alloc; }
121+ DynamicAllocator &getAllocator () {
122+ if (!Alloc) {
123+ Alloc = std::make_unique<DynamicAllocator>();
124+ }
125+
126+ return *Alloc.get ();
127+ }
122128
123129 // / Diagnose any dynamic allocations that haven't been freed yet.
124130 // / Will return \c false if there were any allocations to diagnose,
@@ -164,7 +170,7 @@ class InterpState final : public State, public SourceMapper {
164170 // / Reference to the offset-source mapping.
165171 SourceMapper *M;
166172 // / Allocator used for dynamic allocations performed via the program.
167- DynamicAllocator Alloc;
173+ std::unique_ptr< DynamicAllocator> Alloc;
168174
169175public:
170176 // / Reference to the module containing all bytecode.
You can’t perform that action at this time.
0 commit comments