Skip to content

Commit 8d4aac4

Browse files
committed
[semantic-arc] Now that SILGen only emits qualified ownership memory operations, tighten up the verifier in functions with qualified ownership.
rdar://28685236
1 parent 34ec32b commit 8d4aac4

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ class SILBuilder {
459459

460460
LoadInst *createLoad(SILLocation Loc, SILValue LV,
461461
LoadOwnershipQualifier Qualifier) {
462+
assert((Qualifier != LoadOwnershipQualifier::Unqualified) ||
463+
F.hasUnqualifiedOwnership() &&
464+
"Unqualified inst in qualified function");
465+
assert((Qualifier == LoadOwnershipQualifier::Unqualified) ||
466+
F.hasQualifiedOwnership() &&
467+
"Qualified inst in unqualified function");
462468
assert(LV->getType().isLoadable(F.getModule()));
463469
return insert(new (F.getModule())
464470
LoadInst(getSILDebugLocation(Loc), LV, Qualifier));
@@ -481,6 +487,12 @@ class SILBuilder {
481487

482488
StoreInst *createStore(SILLocation Loc, SILValue Src, SILValue DestAddr,
483489
StoreOwnershipQualifier Qualifier) {
490+
assert((Qualifier != StoreOwnershipQualifier::Unqualified) ||
491+
F.hasUnqualifiedOwnership() &&
492+
"Unqualified inst in qualified function");
493+
assert((Qualifier == StoreOwnershipQualifier::Unqualified) ||
494+
F.hasQualifiedOwnership() &&
495+
"Qualified inst in unqualified function");
484496
return insert(new (F.getModule()) StoreInst(getSILDebugLocation(Loc), Src,
485497
DestAddr, Qualifier));
486498
}

lib/SIL/SILVerifier.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,33 +1123,30 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11231123
case LoadOwnershipQualifier::Unqualified:
11241124
// We should not see loads with unqualified ownership when SILOwnership is
11251125
// enabled.
1126-
requireTrueAndSILOwnership(
1127-
this, F.hasUnqualifiedOwnership(),
1128-
"Load with unqualified ownership in a qualified function");
1126+
require(F.hasUnqualifiedOwnership(),
1127+
"Load with unqualified ownership in a qualified function");
11291128
break;
11301129
case LoadOwnershipQualifier::Copy:
11311130
case LoadOwnershipQualifier::Take:
1132-
requireTrueAndSILOwnership(
1133-
this, F.hasQualifiedOwnership(),
1134-
"Load with qualified ownership in an unqualified function");
1131+
require(F.hasQualifiedOwnership(),
1132+
"Load with qualified ownership in an unqualified function");
11351133
// TODO: Could probably make this a bit stricter.
11361134
require(!LI->getType().isTrivial(LI->getModule()),
11371135
"load [copy] or load [take] can only be applied to non-trivial "
11381136
"types");
11391137
break;
11401138
case LoadOwnershipQualifier::Trivial:
1141-
requireTrueAndSILOwnership(
1142-
this, F.hasQualifiedOwnership(),
1143-
"Load with qualified ownership in an unqualified function");
1139+
require(F.hasQualifiedOwnership(),
1140+
"Load with qualified ownership in an unqualified function");
11441141
require(LI->getType().isTrivial(LI->getModule()),
11451142
"A load with trivial ownership must load a trivial type");
11461143
break;
11471144
}
11481145
}
11491146

11501147
void checkLoadBorrowInst(LoadBorrowInst *LBI) {
1151-
requireTrueAndSILOwnership(
1152-
this, F.hasQualifiedOwnership(),
1148+
require(
1149+
F.hasQualifiedOwnership(),
11531150
"Inst with qualified ownership in a function that is not qualified");
11541151
require(LBI->getType().isObject(), "Result of load must be an object");
11551152
require(LBI->getType().isLoadable(LBI->getModule()),
@@ -1161,8 +1158,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11611158
}
11621159

11631160
void checkEndBorrowInst(EndBorrowInst *EBI) {
1164-
requireTrueAndSILOwnership(
1165-
this, F.hasQualifiedOwnership(),
1161+
require(
1162+
F.hasQualifiedOwnership(),
11661163
"Inst with qualified ownership in a function that is not qualified");
11671164
// We allow for end_borrow to express relationships in between addresses and
11681165
// values, but we require that the types are the same ignoring value
@@ -1188,22 +1185,22 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11881185
case StoreOwnershipQualifier::Unqualified:
11891186
// We should not see loads with unqualified ownership when SILOwnership is
11901187
// enabled.
1191-
requireTrueAndSILOwnership(this, F.hasUnqualifiedOwnership(),
1192-
"Invalid load with unqualified ownership");
1188+
require(F.hasUnqualifiedOwnership(),
1189+
"Qualified store in function with unqualified ownership?!");
11931190
break;
11941191
case StoreOwnershipQualifier::Init:
11951192
case StoreOwnershipQualifier::Assign:
1196-
requireTrueAndSILOwnership(
1197-
this, F.hasQualifiedOwnership(),
1193+
require(
1194+
F.hasQualifiedOwnership(),
11981195
"Inst with qualified ownership in a function that is not qualified");
11991196
// TODO: Could probably make this a bit stricter.
12001197
require(!SI->getSrc()->getType().isTrivial(SI->getModule()),
12011198
"store [init] or store [assign] can only be applied to "
12021199
"non-trivial types");
12031200
break;
12041201
case StoreOwnershipQualifier::Trivial:
1205-
requireTrueAndSILOwnership(
1206-
this, F.hasQualifiedOwnership(),
1202+
require(
1203+
F.hasQualifiedOwnership(),
12071204
"Inst with qualified ownership in a function that is not qualified");
12081205
require(SI->getSrc()->getType().isTrivial(SI->getModule()),
12091206
"A store with trivial ownership must store a trivial type");

0 commit comments

Comments
 (0)