File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -637,9 +637,22 @@ UNOWNED_OR_NONE_DEPENDING_ON_RESULT(AtomicLoad)
637
637
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ExtractElement)
638
638
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(InsertElement)
639
639
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ShuffleVector)
640
- UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ZeroInitializer)
641
640
#undef UNOWNED_OR_NONE_DEPENDING_ON_RESULT
642
641
642
+ #define OWNED_OR_NONE_DEPENDING_ON_RESULT (ID ) \
643
+ ValueOwnershipKind ValueOwnershipKindBuiltinVisitor::visit##ID( \
644
+ BuiltinInst *BI, StringRef Attr) { \
645
+ if (BI->getType ().isTrivial (*BI->getFunction ())) { \
646
+ return OwnershipKind::None; \
647
+ } \
648
+ return OwnershipKind::Owned; \
649
+ }
650
+ // A zeroInitializer may initialize an imported struct with __unsafe_unretained
651
+ // fields. The initialized value is immediately consumed by an assignment, so it
652
+ // must be owned.
653
+ OWNED_OR_NONE_DEPENDING_ON_RESULT (ZeroInitializer)
654
+ #undef OWNED_OR_NONE_DEPENDING_ON_RESULT
655
+
643
656
#define BUILTIN (X,Y,Z )
644
657
#define BUILTIN_SIL_OPERATION (ID, NAME, CATEGORY ) \
645
658
ValueOwnershipKind ValueOwnershipKindBuiltinVisitor::visit##ID( \
Original file line number Diff line number Diff line change
1
+ #import < CoreFoundation/CoreFoundation.h>
2
+
3
+ typedef bool (^boolBlock)(void );
4
+
5
+ struct objc_bool_block {
6
+ __unsafe_unretained boolBlock block;
7
+ };
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -import-objc-header %S/Inputs/objc_init_blocks.h %s -emit-sil -sil-verify-all
2
+
3
+ // REQUIRES: objc_interop
4
+
5
+ // rdar://126142109: import an __unsafe_unretained block as zero-initialized.
6
+ //
7
+ // Make sure that the SIL ownership verifier passes.
8
+ // UnsafeUnretainedBlockClass.init()
9
+ // CHECK-LABEL: sil hidden @$s16objc_init_blocks26UnsafeUnretainedBlockClassCACycfc : $@convention(method) (@owned UnsafeUnretainedBlockClass) -> @owned UnsafeUnretainedBlockClass {
10
+ // CHECK: [[ZI:%.*]] = builtin "zeroInitializer"<objc_bool_block>() : $objc_bool_block
11
+ // CHECK: store [[ZI]] to %{{.*}} : $*objc_bool_block
12
+ // CHECK-LABEL: } // end sil function '$s16objc_init_blocks26UnsafeUnretainedBlockClassCACycfc'
13
+ open class UnsafeUnretainedBlockClass {
14
+ public internal( set) var sc : objc_bool_block
15
+ init ( ) {
16
+ self . sc = objc_bool_block ( )
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments