Skip to content

Commit

Permalink
[Hexagon] Change declaration order of unique_ptr objects to fix crash (
Browse files Browse the repository at this point in the history
…#8859)

A crash occurs when automatically deleting an instance of
CodeGenHexagon because the LLVMContext object has already been
freed. Objects of both types are created using unique_ptr, but
the object managed by the LLVMContext unique_ptr is passed to
CodeGenHexagon object (not as a unique_ptr).

This crash is fixed by moving the declaration of the LLVMContext
object before the CodeGenHexagon object. I'm not sure if this
is the best way to fix this, but it does fix the crash. Also,
in other files, the LLVMContext object is always created first.

Co-authored-by: Cahoon, Brendon <[email protected]>
  • Loading branch information
Krzysztof Parzyszek and bcahoon committed Aug 27, 2021
1 parent 3306857 commit cf19c88
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/target/llvm/codegen_hexagon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ runtime::Module BuildHexagon(IRModule mod, Target target) {
(void)CallOnce;

std::unique_ptr<llvm::TargetMachine> tm = GetLLVMTargetMachine(target);
std::unique_ptr<CodeGenHexagon> cg(new CodeGenHexagon());
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext());
std::unique_ptr<CodeGenHexagon> cg(new CodeGenHexagon());
cg->Init("TVMHexagonModule", tm.get(), ctx.get(), false, false, false);
for (auto kv : mod->functions) {
ICHECK(kv.second->IsInstance<PrimFuncNode>()) << "Can only lower IR Module with PrimFuncs";
Expand Down

0 comments on commit cf19c88

Please sign in to comment.