[Bitcode] Don't confuse type attributes on declaration and call

We should not be using APIs here that try to fetch the attribute
from both the call attributes and the function attributes. Otherwise
we'll try to upgrade a non-existent sret attribute on the call using
the attribute on the function.
This commit is contained in:
Nikita Popov
2022-03-11 17:30:34 +01:00
parent a803cb9e52
commit 2182665305
4 changed files with 22 additions and 14 deletions

View File

@@ -4086,15 +4086,14 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
ArrayRef<unsigned> ArgTyIDs) {
AttributeList Attrs = CB->getAttributes();
for (unsigned i = 0; i != CB->arg_size(); ++i) {
for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet,
Attribute::InAlloca}) {
if (!CB->paramHasAttr(i, Kind) ||
CB->getParamAttr(i, Kind).getValueAsType())
if (!Attrs.hasParamAttr(i, Kind) ||
Attrs.getParamAttr(i, Kind).getValueAsType())
continue;
CB->removeParamAttr(i, Kind);
Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
if (!PtrEltTy)
return error("Missing element type for typed attribute upgrade");
@@ -4114,7 +4113,7 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
llvm_unreachable("not an upgraded type attribute");
}
CB->addParamAttr(i, NewAttr);
Attrs = Attrs.addParamAttribute(Context, i, NewAttr);
}
}
@@ -4125,12 +4124,13 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
if (!CI.hasArg())
continue;
if (CI.isIndirect && !CB->getParamElementType(ArgNo)) {
if (CI.isIndirect && !Attrs.getParamElementType(ArgNo)) {
Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
if (!ElemTy)
return error("Missing element type for inline asm upgrade");
CB->addParamAttr(
ArgNo, Attribute::get(Context, Attribute::ElementType, ElemTy));
Attrs = Attrs.addParamAttribute(
Context, ArgNo,
Attribute::get(Context, Attribute::ElementType, ElemTy));
}
ArgNo++;
@@ -4140,18 +4140,19 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
switch (CB->getIntrinsicID()) {
case Intrinsic::preserve_array_access_index:
case Intrinsic::preserve_struct_access_index:
if (!CB->getParamElementType(0)) {
if (!Attrs.getParamElementType(0)) {
Type *ElTy = getPtrElementTypeByID(ArgTyIDs[0]);
if (!ElTy)
return error("Missing element type for elementtype upgrade");
Attribute NewAttr = Attribute::get(Context, Attribute::ElementType, ElTy);
CB->addParamAttr(0, NewAttr);
Attrs = Attrs.addParamAttribute(Context, 0, NewAttr);
}
break;
default:
break;
}
CB->setAttributes(Attrs);
return Error::success();
}