From 7ff599553ec382e7110ef12c1b1756cc3a56403c Mon Sep 17 00:00:00 2001 From: "Cahoon, Brendon" Date: Mon, 7 Dec 2020 10:42:00 -0600 Subject: [PATCH] [Hexagon] Change declaration order of unique_ptr objects to fix crash 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. --- src/target/llvm/codegen_hexagon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/llvm/codegen_hexagon.cc b/src/target/llvm/codegen_hexagon.cc index 9d324d56887f..26356a547990 100644 --- a/src/target/llvm/codegen_hexagon.cc +++ b/src/target/llvm/codegen_hexagon.cc @@ -704,8 +704,8 @@ runtime::Module BuildHexagon(IRModule mod, Target target) { (void)CallOnce; std::unique_ptr tm = GetLLVMTargetMachine(target); - std::unique_ptr cg(new CodeGenHexagon()); std::unique_ptr ctx(new llvm::LLVMContext()); + std::unique_ptr cg(new CodeGenHexagon()); cg->Init("TVMHexagonModule", tm.get(), ctx.get(), false, false, false); for (auto kv : mod->functions) { ICHECK(kv.second->IsInstance()) << "Can only lower IR Module with PrimFuncs";