Skip to content

[Interop] [SwiftToCxx] New Throw Error Test #59217

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 1 commit into from
Jun 3, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h

// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-functions-errors-execution.o
// RUN: %target-interop-build-swift %S/swift-functions-errors.swift -o %t/swift-functions-errors-execution -Xlinker %t/swift-functions-errors-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain

// RUN: %target-codesign %t/swift-functions-errors-execution
// RUN: %target-run %t/swift-functions-errors-execution | %FileCheck %s

// REQUIRES: executable_test
// XFAIL: *

#include <cassert>
#include "functions.h"

int main() {
static_assert(!noexcept(Functions::emptyThrowFunction()), "noexcept function");
static_assert(!noexcept(Functions::throwFunction()), "noexcept function");

Functions::emptyThrowFunction();
Functions::throwFunction();
return 0;
}

// CHECK: passEmptyThrowFunction
// CHECK-NEXT: passThrowFunction
36 changes: 36 additions & 0 deletions test/Interop/SwiftToCxx/functions/swift-functions-errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h
// RUN: %FileCheck %s < %t/functions.h

// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)

// CHECK-LABEL: namespace Functions {

// CHECK-LABEL: namespace _impl {

// CHECK: SWIFT_EXTERN void $s9Functions18emptyThrowFunctionyyKF(void) SWIFT_CALL; // emptyThrowFunction()
// CHECK: SWIFT_EXTERN void $s9Functions13throwFunctionyyKF(void) SWIFT_CALL; // throwFunction()

// CHECK: }

//XFAIL: *

enum NaiveErrors: Error {
case returnError
case throwError
}

public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }

// CHECK: inline void emptyThrowFunction() {
// CHECK: return _impl::$s9Functions18emptyThrowFunctionyyKF();
// CHECK: }

public func throwFunction() throws {
print("passThrowFunction")
throw NaiveErrors.throwError
}

// CHECK: inline void throwFunction() {
// CHECK: return _impl::$s9Functions13throwFunctionyyKF();
// CHECK: }