Skip to content

Commit

Permalink
Do not use AttributeList::removeParamAttributes (KhronosGroup#1795)
Browse files Browse the repository at this point in the history
AttributeList::removeParamAttributes function sets attribute at specified
index empty so that return value of AttributeList::getNumAttrSet() keeps
unchanged after that call. When call BuiltinCallMutator::removeArg function,
there is assert failure on BuiltinCallMutator::doConversion() since new CallInst
removed arg but still holds attribute of that removed arg.
  • Loading branch information
haonanya1 authored Jan 5, 2023
1 parent af06b97 commit cafd7e0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/SPIRV/SPIRVBuiltinHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,22 @@ BuiltinCallMutator &BuiltinCallMutator::replaceArg(unsigned Index,
BuiltinCallMutator &BuiltinCallMutator::removeArg(unsigned Index) {
// If the argument being dropped is the last one, there is nothing to move, so
// just remove the attributes.
if (Index == Args.size() - 1)
Attrs = Attrs.removeParamAttributes(CI->getContext(), Index);
else
if (Index == Args.size() - 1) {
// TODO: Remove this workaround when LLVM fixes
// https://github.com/llvm/llvm-project/issues/59746 on
// AttributeList::removeParamAttributes function.
// AttributeList::removeParamAttributes function sets attribute at
// specified index empty so that return value of
// AttributeList::getNumAttrSet() keeps unchanged after that call. When call
// BuiltinCallMutator::removeArg function, there is assert failure on
// BuiltinCallMutator::doConversion() since new CallInst removed arg but
// still holds attribute of that removed arg.
SmallVector<AttributeSet, 4> ArgAttrs;
for (unsigned I = 0; I < Index; ++I)
ArgAttrs.push_back(Attrs.getParamAttrs(I));
Attrs = AttributeList::get(CI->getContext(), Attrs.getFnAttrs(),
Attrs.getRetAttrs(), ArgAttrs);
} else
moveAttributes(CI->getContext(), Attrs, Index + 1, Args.size() - Index - 1,
Index);
Args.erase(Args.begin() + Index);
Expand Down

0 comments on commit cafd7e0

Please sign in to comment.