mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[PrintAsClang] Fix thunks for throwing Never funcs
Extend the previous commit’s support for functions that return Never to also properly generate code for *throwing* Never functions. This is a little subtle because: • At the SWIFT_CALL level, throwing Never functions are *not* noreturn • At the thunk level, throwing Never functions are noreturn *only* if you’re using exceptions; if you’re using swift::Expected, they should throw • In either case, the compiler cannot statically prove that thunks are noreturn except on the error path, so we need to add an abort() call on the success path
This commit is contained in:
@@ -89,6 +89,16 @@ int main() {
|
||||
valueError.getMessage();
|
||||
}
|
||||
|
||||
auto expectedResult2 = Functions::throwFunctionWithNeverReturn();
|
||||
if (!expectedResult2.has_value()) {
|
||||
auto error = expectedResult2.error();
|
||||
auto optionalError = error.as<Functions::NaiveErrors>();
|
||||
assert(optionalError.isSome());
|
||||
auto valueError = optionalError.get();
|
||||
assert(valueError == Functions::NaiveErrors::returnError);
|
||||
valueError.getMessage();
|
||||
}
|
||||
|
||||
// Test get T's Value (const)
|
||||
const auto valueExp = testIntValue;
|
||||
if (valueExp.value() == 42)
|
||||
@@ -116,6 +126,8 @@ int main() {
|
||||
// CHECK-NEXT: returnError
|
||||
// CHECK-NEXT: passThrowFunctionWithPossibleReturn
|
||||
// CHECK-NEXT: returnError
|
||||
// CHECK-NEXT: passThrowFunctionWithNeverReturn
|
||||
// CHECK-NEXT: returnError
|
||||
// CHECK-NEXT: Test get T's Value (const)
|
||||
// CHECK-NEXT: Test get T's Value
|
||||
// CHECK-NEXT: testIntValue has a value
|
||||
|
||||
Reference in New Issue
Block a user