Skip to content

Commit 1cbfa1a

Browse files
committed
SILVerifier: verify that retain_value must not have a non-copyable operand
1 parent 3efa770 commit 1cbfa1a

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,6 +3391,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
33913391
void checkRetainValueInst(RetainValueInst *I) {
33923392
require(I->getOperand()->getType().isObject(),
33933393
"Source value should be an object value");
3394+
require(!I->getOperand()->getType().isMoveOnly(),
3395+
"retain value operand type must be copyable");
33943396
require(!F.hasOwnership(),
33953397
"retain_value is only in functions with unqualified ownership");
33963398
}

test/SILOptimizer/simplify_retain_value.sil

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ struct WithDeinit : ~Copyable {
1919
deinit
2020
}
2121

22-
struct Outer : ~Copyable {
23-
var wd: WithDeinit
24-
}
25-
26-
enum EnumWithDeinit: ~Copyable {
27-
case A(Int64)
28-
case B
29-
30-
deinit
31-
}
32-
3322
struct TwoEnums {
3423
var u1: U
3524
var u2: U
@@ -62,16 +51,6 @@ bb0(%0 : $Builtin.Int8, %1 : $Builtin.NativeObject):
6251
return %4 : $(Builtin.Int8, Builtin.NativeObject)
6352
}
6453

65-
// CHECK-LABEL: sil @dont_remove_struct_with_deinit_field
66-
// CHECK: retain_value %0
67-
// CHECK: } // end sil function 'dont_remove_struct_with_deinit_field'
68-
sil @dont_remove_struct_with_deinit_field : $@convention(thin) (Outer) -> () {
69-
bb0(%0 : $Outer):
70-
retain_value %0 : $Outer
71-
%2 = tuple ()
72-
return %2 : $()
73-
}
74-
7554
// CHECK-LABEL: sil @struct_with_two_trivial_enums
7655
// CHECK-NOT: retain_value
7756
// CHECK: } // end sil function 'struct_with_two_trivial_enums'
@@ -138,18 +117,6 @@ bb0(%0 : $@thin U.Type, %1 : $C):
138117
return %6 : $(U, U, U)
139118
}
140119

141-
// CHECK-LABEL: sil @dont_replace_payload_of_enum_with_deinit
142-
// CHECK: %1 = enum
143-
// CHECK: retain_value %1
144-
// CHECK: } // end sil function 'dont_replace_payload_of_enum_with_deinit'
145-
sil @dont_replace_payload_of_enum_with_deinit : $@convention(thin) (Int64) -> () {
146-
bb0(%0 : $Int64):
147-
%1 = enum $EnumWithDeinit, #EnumWithDeinit.A!enumelt, %0 : $Int64
148-
retain_value %1 : $EnumWithDeinit
149-
%3 = tuple ()
150-
return %3 : $()
151-
}
152-
153120
// CHECK-LABEL: sil @release_then_retain_peephole
154121
// CHECK: bb0
155122
// CHECK-NOT: retain_value

0 commit comments

Comments
 (0)