aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-03-11 10:17:31 +0100
committerNikita Popov <npopov@redhat.com>2022-03-11 10:18:42 +0100
commite732f69ea1fdca2c4c0c56600e03f0d8d82e1c29 (patch)
treee92e434d11bcf88d2a784aca332c10a9b0640ff8 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parentdfeb9781557ca655bb99a31f4bcf4d0187d7dd38 (diff)
downloadllvm-e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29.zip
llvm-e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29.tar.gz
llvm-e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29.tar.bz2
[Bitcode] Report error for missing element type for attr upgrade
Otherwise this is going to crash either the TypeFinder or the Verifier.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 214eb15..6a3012d 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -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 "