Skip to content

Commit 3f35f54

Browse files
authored
Merge pull request #68876 from kubamracek/embedded-throw-traps-stdlib
[embedded] In -throws-as-traps mode, avoid swift_willThrow calls from the stdlib
2 parents 9050690 + 2564a25 commit 3f35f54

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/IRGen/GenBuiltin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,13 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
577577
// the error return register. We also have to pass a fake context
578578
// argument due to how swiftcc works in clang.
579579

580-
auto fn = IGF.IGM.getWillThrowFunctionPointer();
581580
auto error = args.claimNext();
581+
582+
if (IGF.IGM.Context.LangOpts.ThrowsAsTraps) {
583+
return;
584+
}
585+
586+
auto fn = IGF.IGM.getWillThrowFunctionPointer();
582587
auto errorTy = IGF.IGM.Context.getErrorExistentialType();
583588
auto errorBuffer = IGF.getCalleeErrorResultSlot(
584589
SILType::getPrimitiveObjectType(errorTy), false);

test/embedded/throw-trap-stdlib.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature Embedded -throws-as-traps | %FileCheck %s
2+
3+
// REQUIRES: VENDOR=apple
4+
// REQUIRES: OS=macosx
5+
6+
public func test() {
7+
withUnsafeTemporaryAllocation(byteCount: MemoryLayout<Int>.size, alignment: MemoryLayout<Int>.alignment) { p in
8+
p[0] = 42
9+
}
10+
}
11+
12+
// CHECK-NOT: swift_willThrow

0 commit comments

Comments
 (0)