Skip to content

Commit a3ee08f

Browse files
committed
[embedded] Use cond_fail in throw-as-traps mode
1 parent a31c338 commit a3ee08f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/SILGen/SILGenStmt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,7 @@ void StmtEmitter::visitReturnStmt(ReturnStmt *S) {
762762

763763
void StmtEmitter::visitThrowStmt(ThrowStmt *S) {
764764
if (SGF.getASTContext().LangOpts.ThrowsAsTraps) {
765-
SGF.B.createBuiltin(S, SGF.SGM.getASTContext().getIdentifier("int_trap"),
766-
SGF.SGM.Types.getEmptyTupleType(), {}, {});
765+
SGF.B.createUnconditionalFail(S, "throw turned into a trap");
767766
SGF.B.createUnreachable(S);
768767
return;
769768
}
@@ -1483,8 +1482,7 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
14831482
"calling emitThrow with invalid throw destination!");
14841483

14851484
if (getASTContext().LangOpts.ThrowsAsTraps) {
1486-
B.createBuiltin(loc, SGM.getASTContext().getIdentifier("int_trap"),
1487-
SGM.Types.getEmptyTupleType(), {}, {});
1485+
B.createUnconditionalFail(loc, "throw turned into a trap");
14881486
B.createUnreachable(loc);
14891487
return;
14901488
}

test/embedded/throw-trap.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ public func catching1() {
2828
// CHECK-TRAPS-SIL: sil @$s4main9throwing1SiyKF : $@convention(thin) () -> (Int, @error any Error) {
2929
// CHECK-TRAPS-SIL-NEXT: bb0:
3030
// CHECK-TRAPS-SIL-NEXT: debug_value
31-
// CHECK-TRAPS-SIL-NEXT: %1 = builtin "int_trap"
31+
// CHECK-TRAPS-SIL-NEXT: %1 = integer_literal $Builtin.Int1, -1
32+
// CHECK-TRAPS-SIL-NEXT: cond_fail %1 : $Builtin.Int1, "throw turned into a trap"
3233
// CHECK-TRAPS-SIL-NEXT: unreachable
3334
// CHECK-TRAPS-SIL-NEXT: }
3435

3536

3637
// CHECK-TRAPS-IR: define {{.*}}@"$s4main9throwing1SiyKF"{{.*}}{
3738
// CHECK-TRAPS-IR-NEXT: entry:
38-
// CHECK-TRAPS-IR-NEXT: call void @llvm.trap()
39+
// CHECK-TRAPS-IR: call void @llvm.trap()
3940
// CHECK-TRAPS-IR-NEXT: unreachable
4041
// CHECK-TRAPS-IR-NEXT: }
42+
// CHECK-TRAPS-IR: define {{.*}}@"$s4main9catching1yyF"{{.*}}{

0 commit comments

Comments
 (0)