This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new cf19c88  [Hexagon] Change declaration order of unique_ptr objects to 
fix crash (#8859)
cf19c88 is described below

commit cf19c889214ca9a1b8c420baff35aa10986b3d9c
Author: Krzysztof Parzyszek <[email protected]>
AuthorDate: Fri Aug 27 05:22:47 2021 -0500

    [Hexagon] Change declaration order of unique_ptr objects to fix crash 
(#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]>
---
 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 9d324d5..26356a5 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<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";

Reply via email to