Skip to content

Commit 2254c58

Browse files
committed
Serialization: Use castTo instead of getAs in a few places to turn null pointer dereferences into assertions
1 parent 676c396 commit 2254c58

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
@@ -1187,7 +1187,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
11871187
// FIXME: Why the arbitrary order difference in IRBuilder type argument?
11881188
ResultVal = Builder.createPartialApply(
11891189
Loc, FnVal, Substitutions, Args,
1190-
closureTy.getAs<SILFunctionType>()->getCalleeConvention());
1190+
closureTy.castTo<SILFunctionType>()->getCalleeConvention());
11911191
break;
11921192
}
11931193
case SILInstructionKind::BuiltinInst: {
@@ -1321,7 +1321,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
13211321
}
13221322
case SILInstructionKind::IntegerLiteralInst: {
13231323
auto Ty = MF->getType(TyID);
1324-
auto intTy = Ty->getAs<BuiltinIntegerType>();
1324+
auto intTy = Ty->castTo<BuiltinIntegerType>();
13251325
Identifier StringVal = MF->getIdentifier(ValID);
13261326
// Build APInt from string.
13271327
APInt value(intTy->getGreatestWidth(), StringVal.str(), 10);
@@ -1332,7 +1332,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
13321332
}
13331333
case SILInstructionKind::FloatLiteralInst: {
13341334
auto Ty = MF->getType(TyID);
1335-
auto floatTy = Ty->getAs<BuiltinFloatType>();
1335+
auto floatTy = Ty->castTo<BuiltinFloatType>();
13361336
Identifier StringVal = MF->getIdentifier(ValID);
13371337
// Build APInt from string.
13381338
APInt bits(floatTy->getBitWidth(), StringVal.str(), 16);
@@ -1562,7 +1562,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
15621562
case SILInstructionKind::StoreUnownedInst: {
15631563
auto Ty = MF->getType(TyID);
15641564
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory);
1565-
auto refType = addrType.getAs<WeakStorageType>();
1565+
auto refType = addrType.castTo<WeakStorageType>();
15661566
auto ValType = SILType::getPrimitiveObjectType(refType.getReferentType());
15671567
bool isInit = (Attr > 0);
15681568
ResultVal = Builder.createStoreUnowned(Loc,
@@ -1574,7 +1574,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
15741574
case SILInstructionKind::StoreWeakInst: {
15751575
auto Ty = MF->getType(TyID);
15761576
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory);
1577-
auto refType = addrType.getAs<WeakStorageType>();
1577+
auto refType = addrType.castTo<WeakStorageType>();
15781578
auto ValType = SILType::getPrimitiveObjectType(refType.getReferentType());
15791579
bool isInit = (Attr > 0);
15801580
ResultVal = Builder.createStoreWeak(Loc,
@@ -1656,7 +1656,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
16561656
// Use OneTypeOneOperand layout where the field number is stored in TypeID.
16571657
auto Ty2 = MF->getType(TyID2);
16581658
SILType ST = getSILType(Ty2, (SILValueCategory)TyCategory2);
1659-
TupleType *TT = ST.getAs<TupleType>();
1659+
TupleType *TT = ST.castTo<TupleType>();
16601660

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

0 commit comments

Comments
 (0)