Skip to content

[Typed throws] Workaround for LLVM miscompile of unused swifterror, add executable test #69043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3775,6 +3775,13 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
errorDest.phis[0]->addIncoming(errorValue, Builder.GetInsertBlock());
} else {
Builder.emitBlock(typedErrorLoadBB);

// Create a dummy use of 'errorValue' in the catch BB to workaround an
// LLVM miscompile that ends up taking the wrong branch if there are no
// uses of 'errorValue' in the catch block.
// FIXME: Remove this when the following radar is fixed: rdar://116636601
Builder.CreatePtrToInt(errorValue, IGM.IntPtrTy);

auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo(errorType));
Explosion errorValue;
ti.loadAsTake(*this, getCalleeTypedErrorResultSlot(errorType), errorValue);
Expand Down
29 changes: 29 additions & 0 deletions test/IRGen/typed_throws_exec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -module-name=test -enable-experimental-feature TypedThrows %s -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test

public enum MyError : Error {
case a
case b
}

public func throwing() throws(MyError) -> Int {
throw MyError.a
}

func wat() {
fatalError("this cannot happen")
}

public func catching() {
do {
try throwing()
wat()
} catch {
}
}

catching()
print("Works!")
// CHECK: Works!