File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -997,6 +997,8 @@ MemoryBehavior SILInstruction::getMemoryBehavior() const {
997
997
return BI->getArguments ().size () > 0
998
998
? MemoryBehavior::MayWrite
999
999
: MemoryBehavior::None;
1000
+ } else if (BInfo.ID == BuiltinValueKind::WillThrow) {
1001
+ return MemoryBehavior::MayRead;
1000
1002
}
1001
1003
if (BInfo.ID != BuiltinValueKind::None)
1002
1004
return BInfo.isReadNone () ? MemoryBehavior::None
@@ -1188,6 +1190,7 @@ bool SILInstruction::mayRelease() const {
1188
1190
if (auto Kind = BI->getBuiltinKind ()) {
1189
1191
switch (Kind.value ()) {
1190
1192
case BuiltinValueKind::CopyArray:
1193
+ case BuiltinValueKind::WillThrow:
1191
1194
return false ;
1192
1195
default :
1193
1196
break ;
@@ -1497,6 +1500,14 @@ bool SILInstruction::isTriviallyDuplicatable() const {
1497
1500
}
1498
1501
1499
1502
bool SILInstruction::mayTrap () const {
1503
+ if (auto *BI = dyn_cast<BuiltinInst>(this )) {
1504
+ if (auto Kind = BI->getBuiltinKind ()) {
1505
+ if (Kind.value () == BuiltinValueKind::WillThrow) {
1506
+ // We don't want willThrow instructions to be removed.
1507
+ return true ;
1508
+ }
1509
+ }
1510
+ }
1500
1511
switch (getKind ()) {
1501
1512
case SILInstructionKind::CondFailInst:
1502
1513
case SILInstructionKind::UnconditionalCheckedCastInst:
Original file line number Diff line number Diff line change @@ -1697,3 +1697,17 @@ bb0(%0 : ${ var Int64 }):
1697
1697
end_access %access : $*Int64
1698
1698
return %val : $Int64
1699
1699
}
1700
+
1701
+ // CHECK-LABEL: sil @willThrow : $@convention(thin) (RefElemNoConflictClass, @guaranteed any Error) -> () {
1702
+ // CHECK: begin_access [modify] [dynamic] [no_nested_conflict]
1703
+ // CHECK-LABEL: } // end sil function 'willThrow'
1704
+
1705
+ sil @willThrow : $@convention(thin) (RefElemNoConflictClass, @guaranteed any Error) -> () {
1706
+ bb0(%0 : $RefElemNoConflictClass, %1 : $any Error):
1707
+ %x = ref_element_addr %0 : $RefElemNoConflictClass, #RefElemNoConflictClass.x
1708
+ %b3 = begin_access [modify] [dynamic] %x : $*Int32
1709
+ %w = builtin "willThrow"(%1 : $any Error) : $()
1710
+ end_access %b3 : $*Int32
1711
+ %10 = tuple ()
1712
+ return %10 : $()
1713
+ }
Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ struct Ptr {
57
57
var p: Int32
58
58
}
59
59
60
+ enum SomeErr : Error {
61
+ case err
62
+ }
60
63
61
64
sil_global public @global_var : $Int32
62
65
@@ -1243,3 +1246,14 @@ sil @test_consuming_in_with_unreachable : $@convention(thin) (@in X) -> () {
1243
1246
bb0(%0 : $*X):
1244
1247
unreachable
1245
1248
}
1249
+
1250
+ // CHECK-LABEL: sil @test_willThrow_builtin
1251
+ // CHECK: [%0: read v**.c*.v**, copy v**.c*.v**]
1252
+ // CHECK: [global: read,copy,deinit_barrier]
1253
+
1254
+ sil @test_willThrow_builtin : $@convention(thin) (@guaranteed any Error) -> () {
1255
+ bb0(%0: $any Error):
1256
+ %1 = builtin "willThrow"(%0 : $any Error) : $()
1257
+ %r = tuple ()
1258
+ return %r : $()
1259
+ }
You can’t perform that action at this time.
0 commit comments