Skip to content

Commit b268698

Browse files
committed
[ownership] Allow mark_uninitialized to only take owned/none ownership parameters.
More explicitly, this disallows guaranteed values to be passed to mark_uninitialized. From the perspective of OSSA, it only makes sense for mark_uninitialized to consume its incoming parameter since we want the underlying allocated value to have its "entire" lifetime "funnel" through the mark_uninitialized. Since if the input value is none, we still accept it, all mark_uninitialized on pointers will not be affected by this. NOTE: Today, mark_uninitialized can not even accept a borrow parameter (we severely restrict what parameters it can take). So I can not actually even write a test for this today since the verifier will run after parsing and assert. But from a modeling perspective and from the perspective of not creating confusion, specifying the ownership of mark_uninitialized more explicitly is good.
1 parent 10936f6 commit b268698

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

lib/SIL/OperandOwnership.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ FORWARD_ANY_OWNERSHIP_INST(ConvertFunction)
333333
FORWARD_ANY_OWNERSHIP_INST(RefToBridgeObject)
334334
FORWARD_ANY_OWNERSHIP_INST(BridgeObjectToRef)
335335
FORWARD_ANY_OWNERSHIP_INST(UnconditionalCheckedCast)
336-
FORWARD_ANY_OWNERSHIP_INST(MarkUninitialized)
337336
FORWARD_ANY_OWNERSHIP_INST(UncheckedEnumData)
338337
FORWARD_ANY_OWNERSHIP_INST(DestructureStruct)
339338
FORWARD_ANY_OWNERSHIP_INST(DestructureTuple)
@@ -355,6 +354,8 @@ FORWARD_ANY_OWNERSHIP_INST(DestructureTuple)
355354
}
356355
FORWARD_CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, MustBeLive, TupleExtract)
357356
FORWARD_CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, MustBeLive, StructExtract)
357+
FORWARD_CONSTANT_OR_NONE_OWNERSHIP_INST(Owned, MustBeInvalidated,
358+
MarkUninitialized)
358359
#undef CONSTANT_OR_NONE_OWNERSHIP_INST
359360

360361
OperandOwnershipKindMap

lib/SIL/ValueOwnership.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ CONSTANT_OWNERSHIP_INST(Unowned, ValueToBridgeObject)
157157
#define CONSTANT_OR_NONE_OWNERSHIP_INST(OWNERSHIP, INST) \
158158
ValueOwnershipKind ValueOwnershipKindClassifier::visit##INST##Inst( \
159159
INST##Inst *I) { \
160-
if (I->getType().isTrivial(*I->getFunction())) { \
160+
if (I->getType().isTrivial(*I->getFunction()) || \
161+
I->getType().isAddress()) { \
161162
return ValueOwnershipKind::None; \
162163
} \
163164
return ValueOwnershipKind::OWNERSHIP; \
@@ -174,6 +175,12 @@ CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, OpenExistentialValue)
174175
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, OpenExistentialBoxValue)
175176
CONSTANT_OR_NONE_OWNERSHIP_INST(Owned, UnconditionalCheckedCastValue)
176177

178+
// Given an owned value, mark_uninitialized always forwards an owned value since
179+
// we want to make sure that all destroys of that value must come through the
180+
// mark_uninitialized (which will happen due to mark_uninitialized consuming the
181+
// value).
182+
CONSTANT_OR_NONE_OWNERSHIP_INST(Owned, MarkUninitialized)
183+
177184
// unchecked_bitwise_cast is a bitwise copy. It produces a trivial or unowned
178185
// result.
179186
//
@@ -249,7 +256,6 @@ FORWARDING_OWNERSHIP_INST(Tuple)
249256
FORWARDING_OWNERSHIP_INST(UncheckedRefCast)
250257
FORWARDING_OWNERSHIP_INST(UnconditionalCheckedCast)
251258
FORWARDING_OWNERSHIP_INST(Upcast)
252-
FORWARDING_OWNERSHIP_INST(MarkUninitialized)
253259
FORWARDING_OWNERSHIP_INST(UncheckedEnumData)
254260
FORWARDING_OWNERSHIP_INST(SelectEnum)
255261
FORWARDING_OWNERSHIP_INST(Enum)

test/SIL/ownership-verifier/undef.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct MyInt {
2020
// CHECK-NEXT: Operand Ownership Map:
2121
// CHECK-NEXT: Op #: 0
2222
// CHECK-NEXT: Ownership Map: -- OperandOwnershipKindMap --
23-
// CHECK-NEXT: unowned: Yes. Liveness: MustBeLive
24-
// CHECK-NEXT: owned: Yes. Liveness: MustBeLive
25-
// CHECK-NEXT: guaranteed: Yes. Liveness: MustBeLive
23+
// CHECK-NEXT: unowned: No.
24+
// CHECK-NEXT: owned: Yes. Liveness: MustBeInvalidated
25+
// CHECK-NEXT: guaranteed: No.
2626
// CHECK-NEXT: any: Yes. Liveness: MustBeLive
2727
// CHECK: Visiting: {{.*}}%1 = mark_uninitialized [var] undef : $Klass
2828
// CHECK-NEXT: Operand Ownership Map:
@@ -36,9 +36,9 @@ struct MyInt {
3636
// CHECK-NEXT: Operand Ownership Map:
3737
// CHECK-NEXT: Op #: 0
3838
// CHECK-NEXT: Ownership Map: -- OperandOwnershipKindMap --
39-
// CHECK-NEXT: unowned: Yes. Liveness: MustBeLive
40-
// CHECK-NEXT: owned: Yes. Liveness: MustBeLive
41-
// CHECK-NEXT: guaranteed: Yes. Liveness: MustBeLive
39+
// CHECK-NEXT: unowned: No.
40+
// CHECK-NEXT: owned: Yes. Liveness: MustBeInvalidated
41+
// CHECK-NEXT: guaranteed: No.
4242
// CHECK-NEXT: any: Yes. Liveness: MustBeLive
4343
// CHECK: Visiting: {{.*}}%4 = struct $MyInt (undef : $Builtin.Int32)
4444
// CHECK-NEXT: Operand Ownership Map:

0 commit comments

Comments
 (0)