Skip to content

Commit cc3e9af

Browse files
committed
SIL: Add some assertions
1 parent cf67a51 commit cc3e9af

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,11 @@ InitExistentialAddrInst *InitExistentialAddrInst::create(
21782178
SILDebugLocation Loc, SILValue Existential, CanType ConcreteType,
21792179
SILType ConcreteLoweredType, ArrayRef<ProtocolConformanceRef> Conformances,
21802180
SILFunction *F) {
2181+
#ifndef NDEBUG
2182+
auto layout = Existential->getType().getASTType().getExistentialLayout();
2183+
assert(layout.getProtocols().size() == Conformances.size());
2184+
#endif
2185+
21812186
SILModule &Mod = F->getModule();
21822187
SmallVector<SILValue, 8> TypeDependentOperands;
21832188
collectTypeDependentOperands(TypeDependentOperands, *F, ConcreteType);
@@ -2196,6 +2201,11 @@ InitExistentialValueInst *InitExistentialValueInst::create(
21962201
SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
21972202
SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
21982203
SILFunction *F) {
2204+
#ifndef NDEBUG
2205+
auto layout = ExistentialType.getASTType().getExistentialLayout();
2206+
assert(layout.getProtocols().size() == Conformances.size());
2207+
#endif
2208+
21992209
SILModule &Mod = F->getModule();
22002210
SmallVector<SILValue, 8> TypeDependentOperands;
22012211
collectTypeDependentOperands(TypeDependentOperands, *F, ConcreteType);
@@ -2212,6 +2222,11 @@ InitExistentialRefInst *InitExistentialRefInst::create(
22122222
SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
22132223
SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
22142224
SILFunction *F, ValueOwnershipKind forwardingOwnershipKind) {
2225+
#ifndef NDEBUG
2226+
auto layout = ExistentialType.getASTType().getExistentialLayout();
2227+
assert(layout.getProtocols().size() == Conformances.size());
2228+
#endif
2229+
22152230
SILModule &Mod = F->getModule();
22162231
SmallVector<SILValue, 8> TypeDependentOperands;
22172232
collectTypeDependentOperands(TypeDependentOperands, *F, ConcreteType);
@@ -2232,6 +2247,11 @@ InitExistentialMetatypeInst::InitExistentialMetatypeInst(
22322247
TypeDependentOperands,
22332248
existentialMetatypeType),
22342249
NumConformances(conformances.size()) {
2250+
#ifndef NDEBUG
2251+
auto layout = existentialMetatypeType.getASTType().getExistentialLayout();
2252+
assert(layout.getProtocols().size() == conformances.size());
2253+
#endif
2254+
22352255
std::uninitialized_copy(conformances.begin(), conformances.end(),
22362256
getTrailingObjects<ProtocolConformanceRef>());
22372257
}

0 commit comments

Comments
 (0)