[Bitcode] Report error for missing element type for attr upgrade
Otherwise this is going to crash either the TypeFinder or the Verifier.
This commit is contained in:
@@ -702,7 +702,7 @@ private:
|
||||
/// 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
|
||||
@@ -4081,8 +4081,8 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
|
||||
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}) {
|
||||
@@ -4093,6 +4093,9 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
|
||||
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:
|
||||
@@ -4121,6 +4124,8 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
|
||||
|
||||
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));
|
||||
}
|
||||
@@ -4134,6 +4139,8 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
|
||||
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);
|
||||
}
|
||||
@@ -4141,6 +4148,8 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
/// Lazily parse the specified function body block.
|
||||
@@ -5067,7 +5076,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
||||
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;
|
||||
}
|
||||
@@ -5161,7 +5171,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
||||
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
|
||||
@@ -5773,7 +5784,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
||||
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 "
|
||||
|
||||
Reference in New Issue
Block a user