Skip to content

Commit 9be606e

Browse files
committed
[semantic-sil] Teach the verifier that an enum return value is a ValueOwnershipKind erasure point.
This means that a trivial enum case of a non-trivial enum can be returned @owned even though it is trivial. We already follow this pattern with bb arguments. rdar://31880847
1 parent 72c8d6a commit 9be606e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ OwnershipCompatibilityUseChecker::visitReturnInst(ReturnInst *RI) {
862862
Base = MergedValue.getValue();
863863
}
864864

865+
if (auto *E = getType().getEnumOrBoundGenericEnum()) {
866+
return visitNonTrivialEnum(E, Base);
867+
}
868+
865869
return {compatibleWithOwnership(Base), true};
866870
}
867871

test/SIL/ownership-verifier/use_verifier.sil

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ bb0(%0 : @trivial $@thick SuperKlass.Type):
351351
return %9999 : $()
352352
}
353353

354+
sil @trivial_enum_return_value : $@convention(thin) () -> @owned Optional<Builtin.NativeObject> {
355+
bb0:
356+
%0 = enum $Optional<Builtin.NativeObject>, #Optional.none!enumelt
357+
return %0 : $Optional<Builtin.NativeObject>
358+
}
359+
354360
//////////////////////
355361
// Terminator Tests //
356362
//////////////////////

0 commit comments

Comments
 (0)