Skip to content

Commit 514cd9c

Browse files
committed
Handle empty case in SILCombine's
SingleBlockOwnedForwardingInstFolder::add function's assert
1 parent ddf8b45 commit 514cd9c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class SingleBlockOwnedForwardingInstFolder {
141141
if (!hasOneNonDebugUse(next))
142142
return false;
143143

144-
assert(getSingleNonDebugUser(rest.back()) == next);
144+
assert(rest.empty() || getSingleNonDebugUser(rest.back()) == next);
145145
rest.push_back(next);
146146
return true;
147147
}

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ struct MyInt {
4848
var value: Builtin.Int32
4949
}
5050

51+
struct NativeObjectStruct {
52+
var ele : Builtin.NativeObject
53+
}
54+
5155
sil [global_init] @global_init_fun : $@convention(thin) () -> Builtin.RawPointer
5256

5357
sil [ossa] @user : $@convention(thin) (@owned Builtin.NativeObject) -> ()
@@ -1373,18 +1377,33 @@ bb0(%0 : @owned $B):
13731377
}
13741378

13751379
// (upcast X2->X (ref-to-object-pointer-inst (object-pointer-to-ref-inst x) typeof(x))) -> x
1376-
// CHECK-LABEL: sil [ossa] @upcast_unchecked_ref_cast_round_trip : $@convention(thin) (@owned E) -> @owned E {
1380+
// CHECK-LABEL: sil [ossa] @upcast_unchecked_ref_cast_round_trip1 : $@convention(thin) (@owned E) -> @owned E {
13771381
// CHECK-NOT: upcast
13781382
// CHECK-NOT: unchecked_ref_cast
1379-
// CHECK: } // end sil function 'upcast_unchecked_ref_cast_round_trip'
1380-
sil [ossa] @upcast_unchecked_ref_cast_round_trip : $@convention(thin) (@owned E) -> @owned E {
1383+
// CHECK: } // end sil function 'upcast_unchecked_ref_cast_round_trip1'
1384+
sil [ossa] @upcast_unchecked_ref_cast_round_trip1 : $@convention(thin) (@owned E) -> @owned E {
13811385
bb0(%0 : @owned $E):
13821386
%1 = upcast %0 : $E to $B
13831387
%2 = unchecked_ref_cast %1 : $B to $Builtin.NativeObject
13841388
%3 = unchecked_ref_cast %2 : $Builtin.NativeObject to $E
13851389
return %3 : $E
13861390
}
13871391

1392+
// CHECK-LABEL: sil [ossa] @upcast_unchecked_ref_cast_round_trip2 :
1393+
// CHECK-NOT: upcast
1394+
// CHECK-NOT: unchecked_ref_cast
1395+
// CHECK-LABEL: } // end sil function 'upcast_unchecked_ref_cast_round_trip2'
1396+
sil [ossa] @upcast_unchecked_ref_cast_round_trip2 : $@convention(method) (@owned E) -> () {
1397+
bb0(%0 : @owned $E):
1398+
%1 = upcast %0 : $E to $B
1399+
debug_value %1 : $B
1400+
%2 = unchecked_ref_cast %1 : $B to $Builtin.NativeObject
1401+
%3 = struct $NativeObjectStruct (%2 : $Builtin.NativeObject)
1402+
destroy_value %3 : $NativeObjectStruct
1403+
%res = tuple ()
1404+
return %res : $()
1405+
}
1406+
13881407
// (load (upcast-addr %x)) -> (upcast-ref (load %x))
13891408
//
13901409
// CHECK-LABEL: sil [ossa] @load_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> @owned B {

0 commit comments

Comments
 (0)