From f13a405cffe76332fa6b1a84cf026d835df71502 Mon Sep 17 00:00:00 2001 From: Sen Yang Date: Tue, 28 Sep 2021 23:08:32 +0800 Subject: [PATCH] [Bugfix] Add nullptr checking for `AttrStmt` with `coproc_uop_scope` attr key (#9123) --- src/target/llvm/codegen_cpu.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc index 40e6245e8beb..c98c23ae8c61 100644 --- a/src/target/llvm/codegen_cpu.cc +++ b/src/target/llvm/codegen_cpu.cc @@ -440,9 +440,11 @@ void CodeGenCPU::CreateComputeScope(const AttrStmtNode* op) { // $xxx_compute_ functions are not global. They should be marked as static (via InternalLinkage) // to call them correctly on MIPS platform (CALL16 issue) // Linkage ld Error: CALL16 reloc at 0x290 not against global symbol - llvm::Function* fcompute = llvm::Function::Create( - ftype, llvm::Function::InternalLinkage, - op->value.as()->value.operator llvm::StringRef(), module_.get()); + const StringImmNode* value = op->value.as(); + ICHECK(value != nullptr); + llvm::Function* fcompute = + llvm::Function::Create(ftype, llvm::Function::InternalLinkage, + value->value.operator llvm::StringRef(), module_.get()); BasicBlock* compute_call_end = CheckCallSuccess(builder_->CreateCall(fcompute, arg_values)); // setup compute function. std::unordered_map new_vmap; @@ -953,7 +955,9 @@ void CodeGenCPU::VisitStmt_(const AssertStmtNode* op) { void CodeGenCPU::VisitStmt_(const AttrStmtNode* op) { if (op->attr_key == tir::attr::coproc_uop_scope) { - this->CreateStaticInit(op->value.as()->value, op->body); + const StringImmNode* value = op->value.as(); + ICHECK(value != nullptr); + this->CreateStaticInit(value->value, op->body); } else if (op->attr_key == tir::attr::compute_scope) { this->CreateComputeScope(op); } else if (tir::attr::IsPragmaKey(op->attr_key)) {