From c123be1fe449983bc0d9cd7644597ed0024900fe Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 10 May 2018 17:49:25 +0300 Subject: [PATCH] Fix incorrect phi node edges in `if` --- dbms/src/Functions/FunctionsConditional.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dbms/src/Functions/FunctionsConditional.h b/dbms/src/Functions/FunctionsConditional.h index ad3e6625396..355e271127e 100644 --- a/dbms/src/Functions/FunctionsConditional.h +++ b/dbms/src/Functions/FunctionsConditional.h @@ -144,8 +144,8 @@ public: auto * cond = values[i](); if (!null_is_false && types[i]->isNullable()) { - returns.emplace_back(head, null); auto * nonnull = llvm::BasicBlock::Create(head->getContext(), "", head->getParent()); + returns.emplace_back(b.GetInsertBlock(), null); b.CreateCondBr(b.CreateExtractValue(cond, {1}), join, nonnull); b.SetInsertPoint(nonnull); b.CreateCondBr(nativeBoolCast(b, removeNullable(types[i]), b.CreateExtractValue(cond, {0})), then, next); @@ -155,12 +155,13 @@ public: b.CreateCondBr(nativeBoolCast(b, types[i], cond), then, next); } b.SetInsertPoint(then); - returns.emplace_back(then, nativeCast(b, types[i + 1], values[i + 1](), type)); + auto * value = nativeCast(b, types[i + 1], values[i + 1](), type); + returns.emplace_back(b.GetInsertBlock(), value); b.CreateBr(join); b.SetInsertPoint(next); - head = next; } - returns.emplace_back(head, nativeCast(b, types.back(), values.back()(), type)); + auto * value = nativeCast(b, types.back(), values.back()(), type); + returns.emplace_back(b.GetInsertBlock(), value); b.CreateBr(join); b.SetInsertPoint(join); auto * phi = b.CreatePHI(toNativeType(b, type), returns.size());