Skip to content

Commit

Permalink
Merge pull request lcompilers#2408 from czgdp1807/ifexpr_fix
Browse files Browse the repository at this point in the history
Create temporary for IfExp outside LLVM loop
  • Loading branch information
certik committed Nov 2, 2023
2 parents c21c0e3 + 833ebd2 commit 35a480b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm_utils->set_api_sc = set_api_sc.get();
}

llvm::AllocaInst* CreateAlloca(llvm::Type* type,
llvm::Value* size=nullptr, const std::string& Name="") {
llvm::BasicBlock &entry_block = builder->GetInsertBlock()->getParent()->getEntryBlock();
llvm::IRBuilder<> builder0(context);
builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt());
return builder0.CreateAlloca(type, size, Name);
}

llvm::Value* CreateLoad(llvm::Value *x) {
return LLVM::CreateLoad(*builder, x);
}
Expand Down Expand Up @@ -5371,7 +5379,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
this->visit_expr_wrapper(x.m_test, true);
llvm::Value *cond = tmp;
llvm::Type* _type = llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get());
llvm::Value* ifexp_res = builder->CreateAlloca(_type);
llvm::Value* ifexp_res = CreateAlloca(_type);
llvm_utils->create_if_else(cond, [&]() {
this->visit_expr_wrapper(x.m_body, true);
builder->CreateStore(tmp, ifexp_res);
Expand Down

0 comments on commit 35a480b

Please sign in to comment.