Skip to content

Commit 5785d45

Browse files
nate-chandlerdrexin
authored andcommitted
[TypedThrows] Don't return undef : void.
LLVM doesn't like undef instances of void. rdar://135631963
1 parent ffd9f20 commit 5785d45

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/IRGen/GenThunk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ void IRGenThunk::emit() {
436436

437437
// Return the result.
438438
if (result.empty()) {
439-
if (emission->getTypedErrorExplosion()) {
439+
if (emission->getTypedErrorExplosion() &&
440+
!IGF.CurFn->getReturnType()->isVoidTy()) {
440441
IGF.Builder.CreateRet(llvm::UndefValue::get(IGF.CurFn->getReturnType()));
441442
} else {
442443
IGF.Builder.CreateRetVoid();

test/IRGen/typed_throws_thunks.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,60 @@ extension P {
6565
public func g3(body: () throws(FixedSize) -> Void) throws(FixedSize) {
6666
}
6767
}
68+
69+
protocol P2 {
70+
// CHECK-LABEL: define{{.*}} swiftcc void @"$s19typed_throws_thunks2P2P1fyyAA1EOYKFTj"(
71+
// CHECK-SAME: ptr noalias swiftself %0,
72+
// CHECK-SAME: ptr noalias nocapture swifterror dereferenceable(8) %1,
73+
// CHECK-SAME: ptr %2, ptr %3
74+
// CHECK-SAME: )
75+
// CHECK-SAME: {
76+
// CHECK: failure:
77+
// CHECK-NOT: ret void undef
78+
// CHECK: ret void
79+
// CHECK: success:
80+
// CHECK-NEXT: ret void
81+
func f() throws(E)
82+
// CHECK-LABEL: define{{.*}} swiftcc i8 @"$s19typed_throws_thunks2P2P1gyys4Int8VYKFTj"(
83+
// CHECk-SAME: ptr noalias swiftself %0
84+
// CHECK-SAME: ptr noalias nocapture swifterror dereferenceable(8) %1
85+
// CHECK-SAME: ptr %2
86+
// CHECK-SAME: ptr %3
87+
// CHECK-SAME: )
88+
// CHECK-SAME: {
89+
// CHECK: failure:
90+
// CHECK-NEXT: ret i8 %{{.*}}
91+
// CHECK: success:
92+
// CHECK-NEXT: ret i8 undef
93+
func g() throws(Int8)
94+
// CHECK-LABEL: define{{.*}} swiftcc i8 @"$s19typed_throws_thunks2P2P1hs4Int8VyAA1EOYKFTj"(
95+
// CHECK-SAME: ptr noalias swiftself %0
96+
// CHECK-SAME: ptr noalias nocapture swifterror dereferenceable(8) %1
97+
// CHECK-SAME: ptr %2
98+
// CHECK-SAME: ptr %3
99+
// CHECK-SAME: )
100+
// CHECK-SAME: {
101+
// CHECK: failure:
102+
// CHECK-NEXT: ret void
103+
// CHECK: success:
104+
// CHECK-NEXT: ret i8 %{{.*}}
105+
func h() throws(E) -> Int8
106+
// CHECK-LABEL: define{{.*}} swiftcc i8 @"$s19typed_throws_thunks2P2P1is4Int8VyAFYKFTj"(
107+
// CHECK-SAME: ptr noalias swiftself %0
108+
// CHECK-SAME: ptr noalias nocapture swifterror dereferenceable(8) %1
109+
// CHECK-SAME: ptr %2
110+
// CHECK-SAME: ptr %3
111+
// CHECK-SAME: )
112+
// CHECK-SAME: {
113+
// CHECK: failure:
114+
// CHECK-NEXT: ret i8 %{{.*}}
115+
// CHECK: success:
116+
// CHECK-NEXT: ret i8 %{{.*}}
117+
func i() throws(Int8) -> Int8
118+
}
119+
120+
extension Int8 : Error {}
121+
122+
enum E: Error {
123+
case e
124+
}

0 commit comments

Comments
 (0)