Skip to content

Commit 6794bba

Browse files
committed
SILVerifier - disallow borrowed address-only aggregates
Verify that address-only values are only forwarded by operations that either move the value or preserve the representation.
1 parent 59eea14 commit 6794bba

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
12681268
if (auto *term = dyn_cast<OwnershipForwardingTermInst>(i)) {
12691269
checkOwnershipForwardingTermInst(term);
12701270
}
1271+
1272+
// Address-only values are potentially move-only, and unmovable if they are
1273+
// borrowed. Ensure that guaranteed address-only values are forwarded with
1274+
// the same representation. Non-destructive projection is
1275+
// allowed. Aggregation and destructive disaggregation is not allowed.
1276+
if (ownership == OwnershipKind::Guaranteed
1277+
&& OwnershipForwardingMixin::isAddressOnly(i)) {
1278+
require(OwnershipForwardingMixin::hasSameRepresentation(i),
1279+
"Forwarding a guaranteed address-only value requires the same "
1280+
"representation since no move or copy is allowed.");
1281+
}
12711282
}
12721283

12731284
void checkDebugVariable(SILInstruction *inst) {

0 commit comments

Comments
 (0)