Skip to content

Commit b254a2a

Browse files
committed
[Typed throws] Workaround for LLVM miscompile of unused swifterror, add executable test
1 parent 18ce3ab commit b254a2a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,13 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
37753775
errorDest.phis[0]->addIncoming(errorValue, Builder.GetInsertBlock());
37763776
} else {
37773777
Builder.emitBlock(typedErrorLoadBB);
3778+
3779+
// Create a dummy use of 'errorValue' in the catch BB to workaround an
3780+
// LLVM miscompile that ends up taking the wrong branch if there are no
3781+
// uses of 'errorValue' in the catch block.
3782+
// FIXME: Remove this when the following radar is fixed: rdar://116636601
3783+
Builder.CreatePtrToInt(errorValue, IGM.IntPtrTy);
3784+
37783785
auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo(errorType));
37793786
Explosion errorValue;
37803787
ti.loadAsTake(*this, getCalleeTypedErrorResultSlot(errorType), errorValue);

test/IRGen/typed_throws_exec.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -module-name=test -enable-experimental-feature TypedThrows %s -o %t/a.out
3+
// RUN: %target-run %t/a.out | %FileCheck %s
4+
// REQUIRES: executable_test
5+
6+
public enum MyError : Error {
7+
case a
8+
case b
9+
}
10+
11+
public func throwing() throws(MyError) -> Int {
12+
throw MyError.a
13+
}
14+
15+
func wat() {
16+
fatalError("this cannot happen")
17+
}
18+
19+
public func catching() {
20+
do {
21+
try throwing()
22+
wat()
23+
} catch {
24+
}
25+
}
26+
27+
catching()
28+
print("Works!")
29+
// CHECK: Works!

0 commit comments

Comments
 (0)