Skip to content

Commit 935e5ec

Browse files
committed
SIL: fix Builder.emitDestroy(of:)
Do nothing for values with address types. Fixes a crash in ConstantCapturePropagation rdar://160816390
1 parent 90a5a0f commit 935e5ec

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ extension Builder {
767767
if value.type.isTrivial(in: value.parentFunction) {
768768
return
769769
}
770+
if value.type.isAddress {
771+
return
772+
}
770773
if value.parentFunction.hasOwnership {
771774
createDestroyValue(operand: value)
772775
} else if value.type.isClass {

test/SILOptimizer/capture_propagation.sil

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ struct S {
803803
}
804804

805805
// CHECK-LABEL: sil [ossa] @testStruct :
806-
// CHECK: [[C]] = function_ref @$s17closureWithStruct4main1SVs5Int32VSbTf3npSSi3Si0_n : $@convention(thin) (Str) -> Builtin.Int32
806+
// CHECK: [[C:%.*]] = function_ref @$s17closureWithStruct4main1SVs5Int32VSbTf3npSSi3Si0_n : $@convention(thin) (Str) -> Builtin.Int32
807807
// CHECK: thin_to_thick_function [[C]] : $@convention(thin) (Str) -> Builtin.Int32 to $@callee_guaranteed (Str) -> Builtin.Int32
808808
// CHECK: } // end sil function 'testStruct'
809809
sil [ossa] @testStruct : $@convention(thin) () -> () {
@@ -843,3 +843,35 @@ bb0(%0 : $Str, %1 : $S):
843843
}
844844

845845
sil @swift_getAtKeyPath : $@convention(thin) <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0, @guaranteed KeyPath<τ_0_0, τ_0_1>) -> @out τ_0_1
846+
847+
struct NonTrivialStruct {
848+
var x: AnyObject
849+
}
850+
851+
sil_global [serialized] @gNonTrivialStruct : $NonTrivialStruct
852+
853+
// CHECK-LABEL: sil [ossa] @test_global_addr :
854+
// CHECK: [[C:%.*]] = function_ref @$s19global_addr_closure17gNonTrivialStructTf3pg_n : $@convention(thin) () -> ()
855+
// CHECK: thin_to_thick_function %2 : $@convention(thin) () -> () to $@callee_owned () -> ()
856+
// CHECK: } // end sil function 'test_global_addr'
857+
sil [ossa] @test_global_addr : $@convention(thin) () -> () {
858+
%3 = global_addr @gNonTrivialStruct : $*NonTrivialStruct
859+
%7 = function_ref @global_addr_closure : $@convention(thin) <T> (@in_guaranteed T) -> ()
860+
%8 = partial_apply %7<NonTrivialStruct>(%3) : $@convention(thin) <T> (@in_guaranteed T) -> ()
861+
destroy_value %8
862+
%r = tuple()
863+
return %r
864+
}
865+
866+
// CHECK-LABEL: sil shared [ossa] @$s19global_addr_closure17gNonTrivialStructTf3pg_n :
867+
// CHECK: bb0:
868+
// CHECK-NEXT: %0 = global_addr @gNonTrivialStruct : $*NonTrivialStruct
869+
// CHECK-NEXT: %1 = tuple ()
870+
// CHECK-NEXT: return %1
871+
// CHECK: } // end sil function '$s19global_addr_closure17gNonTrivialStructTf3pg_n'
872+
sil [ossa] @global_addr_closure : $@convention(thin) <T> (@in_guaranteed T) -> () {
873+
bb0(%0 : $*T):
874+
%r = tuple()
875+
return %r : $()
876+
}
877+

0 commit comments

Comments
 (0)