Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions clang/lib/AST/ByteCode/InterpState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ InterpState::~InterpState() {
void InterpState::cleanup() {
// As a last resort, make sure all pointers still pointing to a dead block
// don't point to it anymore.
Alloc.cleanup();
if (Alloc)
Alloc->cleanup();
}

Frame *InterpState::getCurrentFrame() {
Expand Down Expand Up @@ -103,10 +104,13 @@ void InterpState::deallocate(Block *B) {
}

bool InterpState::maybeDiagnoseDanglingAllocations() {
bool NoAllocationsLeft = !Alloc.hasAllocations();
if (!Alloc)
return true;

bool NoAllocationsLeft = !Alloc->hasAllocations();

if (!checkingPotentialConstantExpression()) {
for (const auto &[Source, Site] : Alloc.allocation_sites()) {
for (const auto &[Source, Site] : Alloc->allocation_sites()) {
assert(!Site.empty());

CCEDiag(Source->getExprLoc(), diag::note_constexpr_memory_leak)
Expand Down
10 changes: 8 additions & 2 deletions clang/lib/AST/ByteCode/InterpState.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ class InterpState final : public State, public SourceMapper {

void setEvalLocation(SourceLocation SL) { this->EvalLocation = SL; }

DynamicAllocator &getAllocator() { return Alloc; }
DynamicAllocator &getAllocator() {
if (!Alloc) {
Alloc = std::make_unique<DynamicAllocator>();
}

return *Alloc.get();
}

/// Diagnose any dynamic allocations that haven't been freed yet.
/// Will return \c false if there were any allocations to diagnose,
Expand Down Expand Up @@ -164,7 +170,7 @@ class InterpState final : public State, public SourceMapper {
/// Reference to the offset-source mapping.
SourceMapper *M;
/// Allocator used for dynamic allocations performed via the program.
DynamicAllocator Alloc;
std::unique_ptr<DynamicAllocator> Alloc;

public:
/// Reference to the module containing all bytecode.
Expand Down