}
Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) {
+ // Bail out for a clearly invalid value. This would make us call resize(0)
+ if (Idx == UINT_MAX)
+ return nullptr;
+
if (Idx >= size())
resize(Idx + 1);
if (Record.size() == 2)
AddressSpace = Record[1];
ResultTy = getTypeByID(Record[0]);
- if (!ResultTy)
+ if (!ResultTy ||
+ !PointerType::isValidElementType(ResultTy))
return Error("Invalid type");
ResultTy = PointerType::get(ResultTy, AddressSpace);
break;
case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
if (Record.size() < 2)
return Error("Invalid record");
- if ((ResultTy = getTypeByID(Record[1])) &&
- StructType::isValidElementType(ResultTy))
- ResultTy = ArrayType::get(ResultTy, Record[0]);
- else
+ ResultTy = getTypeByID(Record[1]);
+ if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
return Error("Invalid type");
+ ResultTy = ArrayType::get(ResultTy, Record[0]);
break;
case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
if (Record.size() < 2)
return Error("Invalid record");
- if ((ResultTy = getTypeByID(Record[1])) &&
- StructType::isValidElementType(ResultTy))
- ResultTy = VectorType::get(ResultTy, Record[0]);
- else
+ ResultTy = getTypeByID(Record[1]);
+ if (!ResultTy || !StructType::isValidElementType(ResultTy))
return Error("Invalid type");
+ ResultTy = VectorType::get(ResultTy, Record[0]);
break;
}
Metadata *InlinedAt =
Record[4] ? MDValueList.getValueFwdRef(Record[4] - 1) : nullptr;
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDLocation, Record[0],
+ GET_OR_DISTINCT(DILocation, Record[0],
(Context, Line, Column, Scope, InlinedAt)),
NextMDValueNo++);
break;
for (unsigned I = 4, E = Record.size(); I != E; ++I)
DwarfOps.push_back(Record[I] ? MDValueList.getValueFwdRef(Record[I] - 1)
: nullptr);
- MDValueList.AssignValue(GET_OR_DISTINCT(GenericDebugNode, Record[0],
+ MDValueList.AssignValue(GET_OR_DISTINCT(GenericDINode, Record[0],
(Context, Tag, Header, DwarfOps)),
NextMDValueNo++);
break;
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDSubrange, Record[0],
+ GET_OR_DISTINCT(DISubrange, Record[0],
(Context, Record[1], unrotateSign(Record[2]))),
NextMDValueNo++);
break;
if (Record.size() != 3)
return Error("Invalid record");
- MDValueList.AssignValue(GET_OR_DISTINCT(MDEnumerator, Record[0],
+ MDValueList.AssignValue(GET_OR_DISTINCT(DIEnumerator, Record[0],
(Context, unrotateSign(Record[1]),
getMDString(Record[2]))),
NextMDValueNo++);
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDBasicType, Record[0],
+ GET_OR_DISTINCT(DIBasicType, Record[0],
(Context, Record[1], getMDString(Record[2]),
Record[3], Record[4], Record[5])),
NextMDValueNo++);
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDDerivedType, Record[0],
+ GET_OR_DISTINCT(DIDerivedType, Record[0],
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4],
getMDOrNull(Record[5]), getMDOrNull(Record[6]),
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDCompositeType, Record[0],
+ GET_OR_DISTINCT(DICompositeType, Record[0],
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4],
getMDOrNull(Record[5]), getMDOrNull(Record[6]),
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDSubroutineType, Record[0],
+ GET_OR_DISTINCT(DISubroutineType, Record[0],
(Context, Record[1], getMDOrNull(Record[2]))),
NextMDValueNo++);
break;
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDFile, Record[0], (Context, getMDString(Record[1]),
+ GET_OR_DISTINCT(DIFile, Record[0], (Context, getMDString(Record[1]),
getMDString(Record[2]))),
NextMDValueNo++);
break;
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDCompileUnit, Record[0],
+ GET_OR_DISTINCT(DICompileUnit, Record[0],
(Context, Record[1], getMDOrNull(Record[2]),
getMDString(Record[3]), Record[4],
getMDString(Record[5]), Record[6],
MDValueList.AssignValue(
GET_OR_DISTINCT(
- MDSubprogram, Record[0],
+ DISubprogram, Record[0],
(Context, getMDOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
getMDOrNull(Record[6]), Record[7], Record[8], Record[9],
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDLexicalBlock, Record[0],
+ GET_OR_DISTINCT(DILexicalBlock, Record[0],
(Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), Record[3], Record[4])),
NextMDValueNo++);
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDLexicalBlockFile, Record[0],
+ GET_OR_DISTINCT(DILexicalBlockFile, Record[0],
(Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), Record[3])),
NextMDValueNo++);
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDNamespace, Record[0],
+ GET_OR_DISTINCT(DINamespace, Record[0],
(Context, getMDOrNull(Record[1]),
getMDOrNull(Record[2]), getMDString(Record[3]),
Record[4])),
if (Record.size() != 3)
return Error("Invalid record");
- MDValueList.AssignValue(GET_OR_DISTINCT(MDTemplateTypeParameter,
+ MDValueList.AssignValue(GET_OR_DISTINCT(DITemplateTypeParameter,
Record[0],
(Context, getMDString(Record[1]),
getMDOrNull(Record[2]))),
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDTemplateValueParameter, Record[0],
+ GET_OR_DISTINCT(DITemplateValueParameter, Record[0],
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
NextMDValueNo++);
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDGlobalVariable, Record[0],
+ GET_OR_DISTINCT(DIGlobalVariable, Record[0],
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]),
getMDOrNull(Record[4]), Record[5],
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDLocalVariable, Record[0],
+ GET_OR_DISTINCT(DILocalVariable, Record[0],
(Context, Record[1], getMDOrNull(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]),
Record[5], getMDOrNull(Record[6]), Record[7],
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDExpression, Record[0],
+ GET_OR_DISTINCT(DIExpression, Record[0],
(Context, makeArrayRef(Record).slice(1))),
NextMDValueNo++);
break;
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDObjCProperty, Record[0],
+ GET_OR_DISTINCT(DIObjCProperty, Record[0],
(Context, getMDString(Record[1]),
getMDOrNull(Record[2]), Record[3],
getMDString(Record[4]), getMDString(Record[5]),
return Error("Invalid record");
MDValueList.AssignValue(
- GET_OR_DISTINCT(MDImportedEntity, Record[0],
+ GET_OR_DISTINCT(DIImportedEntity, Record[0],
(Context, Record[1], getMDOrNull(Record[2]),
getMDOrNull(Record[3]), Record[4],
getMDString(Record[5]))),
return Error("Invalid type for value");
auto *NewGA =
- GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- getDecodedLinkage(Record[2]), "", TheModule);
+ GlobalAlias::create(PTy, getDecodedLinkage(Record[2]), "", TheModule);
// Old bitcode files didn't have visibility field.
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
Type *Ty = nullptr;
if (OpNum + 3 == Record.size())
Ty = getTypeByID(Record[OpNum++]);
+ if (!isa<PointerType>(Op->getType()))
+ return Error("Load operand is not a pointer type");
if (!Ty)
Ty = cast<PointerType>(Op->getType())->getElementType();
else if (Ty != cast<PointerType>(Op->getType())->getElementType())