[llvm] e732f69 - [Bitcode] Report error for missing element type for attr upgrade
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 01:18:49 PST 2022
Author: Nikita Popov
Date: 2022-03-11T10:18:42+01:00
New Revision: e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29
URL: https://github.com/llvm/llvm-project/commit/e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29
DIFF: https://github.com/llvm/llvm-project/commit/e732f69ea1fdca2c4c0c56600e03f0d8d82e1c29.diff
LOG: [Bitcode] Report error for missing element type for attr upgrade
Otherwise this is going to crash either the TypeFinder or the
Verifier.
Added:
llvm/test/Bitcode/Inputs/missing-element-type-for-attribute.bc
Modified:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Bitcode/invalid.test
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 214eb159007fe..6a3012d256380 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -702,7 +702,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
/// 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 "
diff --git a/llvm/test/Bitcode/Inputs/missing-element-type-for-attribute.bc b/llvm/test/Bitcode/Inputs/missing-element-type-for-attribute.bc
new file mode 100644
index 0000000000000..5661399fab91f
Binary files /dev/null and b/llvm/test/Bitcode/Inputs/missing-element-type-for-attribute.bc
diff er
diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test
index ab24a1b2152c7..d5fc75e3b331c 100644
--- a/llvm/test/Bitcode/invalid.test
+++ b/llvm/test/Bitcode/invalid.test
@@ -291,3 +291,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-diimportedentity-record.bc 2
RUN: FileCheck --check-prefix=INVALID-DIIMPORTEDENTITY-RECORD %s
INVALID-DIIMPORTEDENTITY-RECORD: Invalid DIImportedEntity record
+
+RUN: not llvm-dis -disable-output -opaque-pointers %p/Inputs/missing-element-type-for-attribute.bc 2>&1 | \
+RUN: FileCheck --check-prefix=MISSING-ELEMENT-TYPE-FOR-ATTRIBUTE %s
+
+MISSING-ELEMENT-TYPE-FOR-ATTRIBUTE: Missing element type for typed attribute upgrade
More information about the llvm-commits
mailing list