Skip to content

Commit

Permalink
fix: crash by block destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
swift_gan committed Nov 8, 2024
1 parent 4b95372 commit 6f1c3eb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions source/runtime/backend/arm64/jit/translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ void JitTranslator::EmitXor(ir::Inst* inst) {}

void JitTranslator::EmitGoto(ir::Inst* inst) {}

void JitTranslator::EmitSelect(ir::Inst* inst) {}

void JitTranslator::EmitCondSelect(ir::Inst* inst) {}

void JitTranslator::EmitZero(ir::Inst* inst) {}

#undef masm
Expand Down
2 changes: 1 addition & 1 deletion source/runtime/backend/mem_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class MemMap::Impl {

bool Unmap(void* mem, u32 size) { return munmap(mem, size); }

u8* GetBackend() const { return backing_memory; }
[[nodiscard]] u8* GetBackend() const { return backing_memory; }

virtual ~Impl() = default;

Expand Down
2 changes: 1 addition & 1 deletion source/runtime/common/mem_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MemArena {

private:
struct NonTrivialDummy {
NonTrivialDummy() noexcept {}
NonTrivialDummy() noexcept = default;
};

struct Chunk {
Expand Down
14 changes: 7 additions & 7 deletions source/runtime/common/slab_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class SlabAllocator {

void Initialize(size_t size) { size_ = size; }

constexpr std::size_t GetSize() const { return size_; }
[[nodiscard]] std::size_t GetSize() const { return size_; }

Node* GetHead() const { return head; }
[[nodiscard]] Node* GetHead() const { return head; }

void* Allocate();

Expand All @@ -45,11 +45,11 @@ template <typename T> class SlabHeap {
}
}

constexpr bool Contains(uintptr_t addr) const { return start <= addr && addr < end; }
[[nodiscard]] constexpr bool Contains(uintptr_t addr) const { return start <= addr && addr < end; }

constexpr std::size_t GetSlabHeapSize() const { return (end - start) / GetObjectSize(); }
[[nodiscard]] constexpr std::size_t GetSlabHeapSize() const { return (end - start) / GetObjectSize(); }

constexpr std::size_t GetObjectSize() const { return allocator.GetSize(); }
[[nodiscard]] constexpr std::size_t GetObjectSize() const { return allocator.GetSize(); }

std::size_t GetObjectIndexImpl(const void* obj) const {
return (reinterpret_cast<uintptr_t>(obj) - start) / GetObjectSize();
Expand All @@ -74,12 +74,12 @@ template <typename T> class SlabHeap {
}

void Free(void* obj) {
assert(Contains(reinterpret_cast<uintptr_t>(obj)));
ASSERT(Contains(reinterpret_cast<uintptr_t>(obj)));
allocator.Free(obj);
}

void Initialize(void* memory, size_t memory_size) {
assert(memory != nullptr);
ASSERT(memory != nullptr);

auto object_size = sizeof(T);

Expand Down
3 changes: 3 additions & 0 deletions source/runtime/ir/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void Block::DestroyInst(Inst* inst) {
}

void Block::DestroyInstrs() {
for (auto& inst : inst_list) {
inst.DestroyArgs();
}
for (auto it = inst_list.begin(); it != inst_list.end();) {
auto pre = it;
it = inst_list.erase(it);
Expand Down
3 changes: 1 addition & 2 deletions source/runtime/ir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ void Inst::DestroyArg(u8 arg_idx) {
}
}
params.Destroy();
} else {
arg = {};
}
arg = {};
}

void Inst::DestroyArgs() {
Expand Down
2 changes: 2 additions & 0 deletions source/runtime/ir/ir.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ INST(CompareAndSwap, Value, Value, Value, Value)
INST(UniformBarrier, Void)
INST(Goto, Value, BOOL)
INST(NotGoto, Value, BOOL)
INST(Select, Value, BOOL, Value, Value)
INST(CondSelect, Value, Cond, Value, Value)
INST(BindLabel, Void, Value)
INST(CallLambda, Value, Lambda, Value, Value, Value)
INST(CallLocation, Value, Lambda, Params)
Expand Down

0 comments on commit 6f1c3eb

Please sign in to comment.