aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-03-11 17:30:34 +0100
committerNikita Popov <npopov@redhat.com>2022-03-11 17:32:40 +0100
commit2182665305d90ae7d0d2b573dced9ef0ef414a9a (patch)
treefc5be7a762f17dbc1efd9d6844ce04b445a15a6a /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parenta803cb9e52435b8f981328d79bc322ab09416cbd (diff)
downloadllvm-2182665305d90ae7d0d2b573dced9ef0ef414a9a.zip
llvm-2182665305d90ae7d0d2b573dced9ef0ef414a9a.tar.gz
llvm-2182665305d90ae7d0d2b573dced9ef0ef414a9a.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp21
1 files changed, 11 insertions, 10 deletions
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<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();
}