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 @@ -652,9 +652,22 @@ UNOWNED_OR_NONE_DEPENDING_ON_RESULT(AtomicLoad)
652652UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ExtractElement)
653653UNOWNED_OR_NONE_DEPENDING_ON_RESULT(InsertElement)
654654UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ShuffleVector)
655- UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ZeroInitializer)
656655#undef UNOWNED_OR_NONE_DEPENDING_ON_RESULT
657656
657+ #define OWNED_OR_NONE_DEPENDING_ON_RESULT (ID ) \
658+ ValueOwnershipKind ValueOwnershipKindBuiltinVisitor::visit##ID( \
659+ BuiltinInst *BI, StringRef Attr) { \
660+ if (BI->getType ().isTrivial (*BI->getFunction ())) { \
661+ return OwnershipKind::None; \
662+ } \
663+ return OwnershipKind::Owned; \
664+ }
665+ // A zeroInitializer may initialize an imported struct with __unsafe_unretained
666+ // fields. The initialized value is immediately consumed by an assignment, so it
667+ // must be owned.
668+ OWNED_OR_NONE_DEPENDING_ON_RESULT (ZeroInitializer)
669+ #undef OWNED_OR_NONE_DEPENDING_ON_RESULT
670+
658671#define BUILTIN (X,Y,Z )
659672#define BUILTIN_SIL_OPERATION (ID, NAME, CATEGORY ) \
660673 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