Skip to content

Commit f2975a8

Browse files
committed
Serialization: Use castTo instead of getAs in a few places to turn null pointer dereferences into assertions
1 parent 82e08e0 commit f2975a8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
11831183
// FIXME: Why the arbitrary order difference in IRBuilder type argument?
11841184
ResultVal = Builder.createPartialApply(
11851185
Loc, FnVal, Substitutions, Args,
1186-
closureTy.getAs<SILFunctionType>()->getCalleeConvention());
1186+
closureTy.castTo<SILFunctionType>()->getCalleeConvention());
11871187
break;
11881188
}
11891189
case SILInstructionKind::BuiltinInst: {
@@ -1317,7 +1317,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
13171317
}
13181318
case SILInstructionKind::IntegerLiteralInst: {
13191319
auto Ty = MF->getType(TyID);
1320-
auto intTy = Ty->getAs<BuiltinIntegerType>();
1320+
auto intTy = Ty->castTo<BuiltinIntegerType>();
13211321
Identifier StringVal = MF->getIdentifier(ValID);
13221322
// Build APInt from string.
13231323
APInt value(intTy->getGreatestWidth(), StringVal.str(), 10);
@@ -1328,7 +1328,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
13281328
}
13291329
case SILInstructionKind::FloatLiteralInst: {
13301330
auto Ty = MF->getType(TyID);
1331-
auto floatTy = Ty->getAs<BuiltinFloatType>();
1331+
auto floatTy = Ty->castTo<BuiltinFloatType>();
13321332
Identifier StringVal = MF->getIdentifier(ValID);
13331333
// Build APInt from string.
13341334
APInt bits(floatTy->getBitWidth(), StringVal.str(), 16);
@@ -1558,7 +1558,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
15581558
case SILInstructionKind::StoreUnownedInst: {
15591559
auto Ty = MF->getType(TyID);
15601560
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory);
1561-
auto refType = addrType.getAs<WeakStorageType>();
1561+
auto refType = addrType.castTo<WeakStorageType>();
15621562
auto ValType = SILType::getPrimitiveObjectType(refType.getReferentType());
15631563
bool isInit = (Attr > 0);
15641564
ResultVal = Builder.createStoreUnowned(Loc,
@@ -1570,7 +1570,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
15701570
case SILInstructionKind::StoreWeakInst: {
15711571
auto Ty = MF->getType(TyID);
15721572
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory);
1573-
auto refType = addrType.getAs<WeakStorageType>();
1573+
auto refType = addrType.castTo<WeakStorageType>();
15741574
auto ValType = SILType::getPrimitiveObjectType(refType.getReferentType());
15751575
bool isInit = (Attr > 0);
15761576
ResultVal = Builder.createStoreWeak(Loc,
@@ -1652,7 +1652,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
16521652
// Use OneTypeOneOperand layout where the field number is stored in TypeID.
16531653
auto Ty2 = MF->getType(TyID2);
16541654
SILType ST = getSILType(Ty2, (SILValueCategory)TyCategory2);
1655-
TupleType *TT = ST.getAs<TupleType>();
1655+
TupleType *TT = ST.castTo<TupleType>();
16561656

16571657
auto ResultTy = TT->getElement(TyID).getType();
16581658
switch (OpCode) {
@@ -1675,7 +1675,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
16751675
// Format: a type followed by a list of values. A value is expressed by
16761676
// 2 IDs: ValueID, ValueResultNumber.
16771677
auto Ty = MF->getType(TyID);
1678-
TupleType *TT = Ty->getAs<TupleType>();
1678+
TupleType *TT = Ty->castTo<TupleType>();
16791679
assert(TT && "Type of a TupleInst should be TupleType");
16801680
SmallVector<SILValue, 4> OpList;
16811681
for (unsigned I = 0, E = ListOfValues.size(); I < E; I++) {

0 commit comments

Comments
 (0)