/// Upgrades old-style typeless byval/sret/inalloca attributes by adding the
/// corresponding argument's pointee type. Also upgrades intrinsics that now
/// require an elementtype attribute.
- void propagateAttributeTypes(CallBase *CB, ArrayRef<unsigned> ArgsTys);
+ Error propagateAttributeTypes(CallBase *CB, ArrayRef<unsigned> ArgsTys);
/// Converts alignment exponent (i.e. power of two (or zero)) to the
/// corresponding alignment to use. If alignment is too large, returns
return Error::success();
}
-void BitcodeReader::propagateAttributeTypes(CallBase *CB,
- ArrayRef<unsigned> ArgTyIDs) {
+Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
+ ArrayRef<unsigned> ArgTyIDs) {
for (unsigned i = 0; i != CB->arg_size(); ++i) {
for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet,
Attribute::InAlloca}) {
CB->removeParamAttr(i, Kind);
Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
+ if (!PtrEltTy)
+ return error("Missing element type for typed attribute upgrade");
+
Attribute NewAttr;
switch (Kind) {
case Attribute::ByVal:
if (CI.isIndirect && !CB->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));
}
case Intrinsic::preserve_struct_access_index:
if (!CB->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);
}
default:
break;
}
+
+ return Error::success();
}
/// Lazily parse the specified function body block.
cast<InvokeInst>(I)->setCallingConv(
static_cast<CallingConv::ID>(CallingConv::MaxID & CCInfo));
cast<InvokeInst>(I)->setAttributes(PAL);
- propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs);
+ if (Error Err = propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs))
+ return Err;
break;
}
cast<CallBrInst>(I)->setCallingConv(
static_cast<CallingConv::ID>((0x7ff & CCInfo) >> bitc::CALL_CCONV));
cast<CallBrInst>(I)->setAttributes(PAL);
- propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs);
+ if (Error Err = propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs))
+ return Err;
break;
}
case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
TCK = CallInst::TCK_NoTail;
cast<CallInst>(I)->setTailCallKind(TCK);
cast<CallInst>(I)->setAttributes(PAL);
- propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs);
+ if (Error Err = propagateAttributeTypes(cast<CallBase>(I), ArgTyIDs))
+ return Err;
if (FMF.any()) {
if (!isa<FPMathOperator>(I))
return error("Fast-math-flags specified for call without "