Skip to content

Commit d3f775c

Browse files
jaladreipsigcbot
authored andcommitted
Fix out of bounds crash in InlineHelper
Fix out of bounds crash in InlineHelper
1 parent 9c8e84c commit d3f775c

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

IGC/common/LLVMUtils.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -954,29 +954,23 @@ void InlineHelper::InlineAndOptimize(CallInst* callInst)
954954
// Merge static array allocas to reduce the use of private
955955
// memory. This is a similar optimization that exists in
956956
// the inliner, see mergeInlinedArrayAllocas().
957-
if (perFnAllocas.empty())
958-
{
959-
for (AllocaInst* allocaInst : IFI.StaticAllocas)
957+
llvm::erase_if(
958+
IFI.StaticAllocas,
959+
[](AllocaInst* I)
960960
{
961-
if (!allocaInst->isArrayAllocation() &&
962-
allocaInst->getAllocatedType()->isArrayTy())
963-
{
964-
perFnAllocas.push_back(allocaInst);
965-
}
961+
return I->isArrayAllocation() || !I->getAllocatedType()->isArrayTy();
966962
}
967-
}
968-
else
963+
);
964+
965+
auto staticAlloca = IFI.StaticAllocas.begin();
966+
for (auto* fnAlloca : perFnAllocas)
969967
{
970-
auto it = perFnAllocas.begin();
971-
for (AllocaInst* allocaInst : IFI.StaticAllocas)
972-
{
973-
if (!allocaInst->isArrayAllocation() &&
974-
allocaInst->getAllocatedType()->isArrayTy())
975-
{
976-
IGC_ASSERT((*it)->getAllocatedType() == allocaInst->getAllocatedType());
977-
allocaInst->replaceAllUsesWith(*it);
978-
++it;
979-
}
980-
}
968+
if ((*staticAlloca)->getAllocatedType() == fnAlloca->getAllocatedType())
969+
(*staticAlloca)->replaceAllUsesWith(fnAlloca);
970+
971+
if (++staticAlloca == IFI.StaticAllocas.end())
972+
return;
981973
}
974+
975+
perFnAllocas.append(staticAlloca, IFI.StaticAllocas.end());
982976
}

0 commit comments

Comments
 (0)