[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:
Becca Royal-Gordon
2024-03-18 11:32:35 -07:00
parent 80f38be3b8
commit a02698ba06
7 changed files with 54 additions and 5 deletions

View File

@@ -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