@@ -702,7 +702,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
702
702
// / Upgrades old-style typeless byval/sret/inalloca attributes by adding the
703
703
// / corresponding argument's pointee type. Also upgrades intrinsics that now
704
704
// / require an elementtype attribute.
705
- void propagateAttributeTypes (CallBase *CB, ArrayRef<unsigned > ArgsTys);
705
+ Error propagateAttributeTypes (CallBase *CB, ArrayRef<unsigned > ArgsTys);
706
706
707
707
// / Converts alignment exponent (i.e. power of two (or zero)) to the
708
708
// / corresponding alignment to use. If alignment is too large, returns
@@ -4081,8 +4081,8 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
4081
4081
return Error::success ();
4082
4082
}
4083
4083
4084
- void BitcodeReader::propagateAttributeTypes (CallBase *CB,
4085
- ArrayRef<unsigned > ArgTyIDs) {
4084
+ Error BitcodeReader::propagateAttributeTypes (CallBase *CB,
4085
+ ArrayRef<unsigned > ArgTyIDs) {
4086
4086
for (unsigned i = 0 ; i != CB->arg_size (); ++i) {
4087
4087
for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet,
4088
4088
Attribute::InAlloca}) {
@@ -4093,6 +4093,9 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
4093
4093
CB->removeParamAttr (i, Kind);
4094
4094
4095
4095
Type *PtrEltTy = getPtrElementTypeByID (ArgTyIDs[i]);
4096
+ if (!PtrEltTy)
4097
+ return error (" Missing element type for typed attribute upgrade" );
4098
+
4096
4099
Attribute NewAttr;
4097
4100
switch (Kind) {
4098
4101
case Attribute::ByVal:
@@ -4121,6 +4124,8 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
4121
4124
4122
4125
if (CI.isIndirect && !CB->getParamElementType (ArgNo)) {
4123
4126
Type *ElemTy = getPtrElementTypeByID (ArgTyIDs[ArgNo]);
4127
+ if (!ElemTy)
4128
+ return error (" Missing element type for inline asm upgrade" );
4124
4129
CB->addParamAttr (
4125
4130
ArgNo, Attribute::get (Context, Attribute::ElementType, ElemTy));
4126
4131
}
@@ -4134,13 +4139,17 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
4134
4139
case Intrinsic::preserve_struct_access_index:
4135
4140
if (!CB->getParamElementType (0 )) {
4136
4141
Type *ElTy = getPtrElementTypeByID (ArgTyIDs[0 ]);
4142
+ if (!ElTy)
4143
+ return error (" Missing element type for elementtype upgrade" );
4137
4144
Attribute NewAttr = Attribute::get (Context, Attribute::ElementType, ElTy);
4138
4145
CB->addParamAttr (0 , NewAttr);
4139
4146
}
4140
4147
break ;
4141
4148
default :
4142
4149
break ;
4143
4150
}
4151
+
4152
+ return Error::success ();
4144
4153
}
4145
4154
4146
4155
// / Lazily parse the specified function body block.
@@ -5067,7 +5076,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
5067
5076
cast<InvokeInst>(I)->setCallingConv (
5068
5077
static_cast <CallingConv::ID>(CallingConv::MaxID & CCInfo));
5069
5078
cast<InvokeInst>(I)->setAttributes (PAL);
5070
- propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs);
5079
+ if (Error Err = propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs))
5080
+ return Err;
5071
5081
5072
5082
break ;
5073
5083
}
@@ -5161,7 +5171,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
5161
5171
cast<CallBrInst>(I)->setCallingConv (
5162
5172
static_cast <CallingConv::ID>((0x7ff & CCInfo) >> bitc::CALL_CCONV));
5163
5173
cast<CallBrInst>(I)->setAttributes (PAL);
5164
- propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs);
5174
+ if (Error Err = propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs))
5175
+ return Err;
5165
5176
break ;
5166
5177
}
5167
5178
case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
@@ -5773,7 +5784,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
5773
5784
TCK = CallInst::TCK_NoTail;
5774
5785
cast<CallInst>(I)->setTailCallKind (TCK);
5775
5786
cast<CallInst>(I)->setAttributes (PAL);
5776
- propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs);
5787
+ if (Error Err = propagateAttributeTypes (cast<CallBase>(I), ArgTyIDs))
5788
+ return Err;
5777
5789
if (FMF.any ()) {
5778
5790
if (!isa<FPMathOperator>(I))
5779
5791
return error (" Fast-math-flags specified for call without "
0 commit comments