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 () { return Current; }
@@ -99,10 +100,13 @@ void InterpState::deallocate(Block *B) {
99100}
100101
101102bool InterpState::maybeDiagnoseDanglingAllocations () {
102- bool NoAllocationsLeft = !Alloc.hasAllocations ();
103+ if (!Alloc)
104+ return true ;
105+
106+ bool NoAllocationsLeft = !Alloc->hasAllocations ();
103107
104108 if (!checkingPotentialConstantExpression ()) {
105- for (const auto &[Source, Site] : Alloc. allocation_sites ()) {
109+ for (const auto &[Source, Site] : Alloc-> allocation_sites ()) {
106110 assert (!Site.empty ());
107111
108112 CCEDiag (Source->getExprLoc (), diag::note_constexpr_memory_leak)
Original file line number Diff line number Diff line change @@ -115,7 +115,13 @@ class InterpState final : public State, public SourceMapper {
115115
116116 void setEvalLocation (SourceLocation SL) { this ->EvalLocation = SL; }
117117
118- DynamicAllocator &getAllocator () { return Alloc; }
118+ DynamicAllocator &getAllocator () {
119+ if (!Alloc) {
120+ Alloc = std::make_unique<DynamicAllocator>();
121+ }
122+
123+ return *Alloc.get ();
124+ }
119125
120126 // / Diagnose any dynamic allocations that haven't been freed yet.
121127 // / Will return \c false if there were any allocations to diagnose,
@@ -161,7 +167,7 @@ class InterpState final : public State, public SourceMapper {
161167 // / Reference to the offset-source mapping.
162168 SourceMapper *M;
163169 // / Allocator used for dynamic allocations performed via the program.
164- DynamicAllocator Alloc;
170+ std::unique_ptr< DynamicAllocator> Alloc;
165171
166172public:
167173 // / Reference to the module containing all bytecode.
You can’t perform that action at this time.
0 commit comments