From 2182665305d90ae7d0d2b573dced9ef0ef414a9a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Mar 2022 17:30:34 +0100 Subject: [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. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index f6f0c92..5a667f5 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4086,15 +4086,14 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) { Error BitcodeReader::propagateAttributeTypes(CallBase *CB, ArrayRef 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(); } -- cgit v1.1