Skip to content

Commit c4e4d4d

Browse files
committed
[SIGen] UnsafeCastExpr: Use forwarding cast instead of bitcast
Forwarding cast handles ownership correctly and doesn't disable optimizations unlike bitcast.
1 parent cc13060 commit c4e4d4d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ RValue RValueEmitter::visitUnsafeCastExpr(UnsafeCastExpr *E, SGFContext C) {
21452145
ASSERT(resultType.isAddress());
21462146
result = SGF.B.createUncheckedAddrCast(E, original, resultType);
21472147
} else {
2148-
result = SGF.B.createUncheckedBitCast(E, original, resultType);
2148+
result = SGF.B.createUncheckedForwardingCast(E, original, resultType);
21492149
}
21502150

21512151
return RValue(SGF, E, result);

test/SILGen/sendable_to_any_for_generic_arguments.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extension Array where Element == Any {
1515
}
1616

1717
// CHECK-LABEL: sil hidden [ossa] @$s37sendable_to_any_for_generic_arguments31test_conditional_on_collections1uyAA4UserC_tF
18-
// CHECK: unchecked_bitwise_cast {{.*}} to $Dictionary<String, Any>
19-
// CHECK: unchecked_bitwise_cast {{.*}} to $Array<Any>
18+
// CHECK: unchecked_value_cast {{.*}} to $Dictionary<String, Any>
19+
// CHECK: unchecked_value_cast {{.*}} to $Array<Any>
2020
func test_conditional_on_collections(u: User) {
2121
u.dict.onlyWhenValueAny()
2222
u.arr.onlyWhenValueAny()
@@ -41,10 +41,10 @@ extension Array where Element == any Sendable {
4141
}
4242

4343
// CHECK-LABEL: sil hidden [ossa] @$s37sendable_to_any_for_generic_arguments41test_no_ambiguity_with_Sendable_extension1uyAA4UserC_tF
44-
// CHECK-NOT: unchecked_bitwise_cast {{.*}}
44+
// CHECK-NOT: unchecked_value_cast {{.*}}
4545
// CHECK: [[DICT_METHOD_REF:%.*]] = function_ref @$sSD37sendable_to_any_for_generic_argumentsSSRszs8Sendable_pRs_rlE11noAmbiguityyyF : $@convention(method) (@guaranteed Dictionary<String, any Sendable>) -> ()
4646
// CHECK-NEXT: {{.*}} = apply [[DICT_METHOD_REF]]({{.*}}) : $@convention(method) (@guaranteed Dictionary<String, any Sendable>) -> ()
47-
// CHECK-NOT: unchecked_bitwise_cast {{.*}}
47+
// CHECK-NOT: unchecked_value_cast {{.*}}
4848
// CHECK: [[ARR_METHOD_REF:%.*]] = function_ref @$sSa37sendable_to_any_for_generic_argumentss8Sendable_pRszlE11noAmbiguityyyF : $@convention(method) (@guaranteed Array<any Sendable>) -> ()
4949
// CHECK-NEXT: {{.*}} = apply [[ARR_METHOD_REF]]({{.*}}) : $@convention(method) (@guaranteed Array<any Sendable>) -> ()
5050
func test_no_ambiguity_with_Sendable_extension(u: User) {

0 commit comments

Comments
 (0)