mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This macro applies always_inline in addition to inline. It also applies artificial, which lets debugger know that this is an artificial function. The used attribute is added in debug builds to ensure that the symbol is emitted in the binary so that LLDB can invoke it.
129 lines
5.1 KiB
Swift
129 lines
5.1 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
|
|
// RUN: %FileCheck %s < %t/functions.h
|
|
|
|
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-function)
|
|
|
|
// CHECK-LABEL: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
|
|
|
|
// CHECK-LABEL: namespace _impl {
|
|
|
|
// CHECK: SWIFT_EXTERN void $s9Functions18emptyThrowFunctionyyKF(SWIFT_CONTEXT void * _Nonnull _ctx, SWIFT_ERROR_RESULT void * _Nullable * _Nullable _error) SWIFT_CALL; // emptyThrowFunction()
|
|
// CHECK: SWIFT_EXTERN void $s9Functions18testDestroyedErroryyKF(SWIFT_CONTEXT void * _Nonnull _ctx, SWIFT_ERROR_RESULT void * _Nullable * _Nullable _error) SWIFT_CALL; // testDestroyedError()
|
|
// CHECK: SWIFT_EXTERN void $s9Functions13throwFunctionyyKF(SWIFT_CONTEXT void * _Nonnull _ctx, SWIFT_ERROR_RESULT void * _Nullable * _Nullable _error) SWIFT_CALL; // throwFunction()
|
|
// CHECK: SWIFT_EXTERN ptrdiff_t $s9Functions31throwFunctionWithPossibleReturnyS2iKF(ptrdiff_t a, SWIFT_CONTEXT void * _Nonnull _ctx, SWIFT_ERROR_RESULT void * _Nullable * _Nullable _error) SWIFT_CALL; // throwFunctionWithPossibleReturn(_:)
|
|
// CHECK: SWIFT_EXTERN ptrdiff_t $s9Functions23throwFunctionWithReturnSiyKF(SWIFT_CONTEXT void * _Nonnull _ctx, SWIFT_ERROR_RESULT void * _Nullable * _Nullable _error) SWIFT_CALL; // throwFunctionWithReturn()
|
|
|
|
|
|
// CHECK: }
|
|
|
|
@_expose(Cxx)
|
|
public enum NaiveErrors : Error {
|
|
case returnError
|
|
case throwError
|
|
|
|
public func getMessage() {
|
|
print(self)
|
|
}
|
|
}
|
|
|
|
@_expose(Cxx)
|
|
public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> emptyThrowFunction() SWIFT_SYMBOL("s:9Functions18emptyThrowFunctionyyKF") {
|
|
// CHECK: void* opaqueError = nullptr;
|
|
// CHECK: void* _ctx = nullptr;
|
|
// CHECK: _impl::$s9Functions18emptyThrowFunctionyyKF(_ctx, &opaqueError);
|
|
// CHECK: if (opaqueError != nullptr)
|
|
// CHECK: #ifdef __cpp_exceptions
|
|
// CHECK: throw (Swift::Error(opaqueError));
|
|
// CHECK: #else
|
|
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
|
|
// CHECK: #endif
|
|
// CHECK: }
|
|
|
|
class TestDestroyed {
|
|
deinit {
|
|
print("Test destroyed")
|
|
}
|
|
}
|
|
|
|
@_expose(Cxx)
|
|
public struct DestroyedError : Error {
|
|
let t = TestDestroyed()
|
|
}
|
|
|
|
@_expose(Cxx)
|
|
public func testDestroyedError() throws { throw DestroyedError() }
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> testDestroyedError() SWIFT_SYMBOL("s:9Functions18testDestroyedErroryyKF") {
|
|
// CHECK: void* opaqueError = nullptr;
|
|
// CHECK: void* _ctx = nullptr;
|
|
// CHECK: _impl::$s9Functions18testDestroyedErroryyKF(_ctx, &opaqueError);
|
|
// CHECK: if (opaqueError != nullptr)
|
|
// CHECK: #ifdef __cpp_exceptions
|
|
// CHECK: throw (Swift::Error(opaqueError));
|
|
// CHECK: #else
|
|
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
|
|
// CHECK: #endif
|
|
// CHECK: }
|
|
|
|
@_expose(Cxx)
|
|
public func throwFunction() throws {
|
|
print("passThrowFunction")
|
|
throw NaiveErrors.throwError
|
|
}
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> throwFunction() SWIFT_SYMBOL("s:9Functions13throwFunctionyyKF") {
|
|
// CHECK: void* opaqueError = nullptr;
|
|
// CHECK: void* _ctx = nullptr;
|
|
// CHECK: _impl::$s9Functions13throwFunctionyyKF(_ctx, &opaqueError);
|
|
// CHECK: if (opaqueError != nullptr)
|
|
// CHECK: #ifdef __cpp_exceptions
|
|
// CHECK: throw (Swift::Error(opaqueError));
|
|
// CHECK: #else
|
|
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
|
|
// CHECK: #endif
|
|
// CHECK: }
|
|
|
|
@_expose(Cxx)
|
|
public func throwFunctionWithPossibleReturn(_ a: Int) throws -> Int {
|
|
print("passThrowFunctionWithPossibleReturn")
|
|
if (a == 0) {
|
|
throw NaiveErrors.returnError
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<swift::Int> throwFunctionWithPossibleReturn(swift::Int a) SWIFT_SYMBOL("s:9Functions31throwFunctionWithPossibleReturnyS2iKF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK: void* opaqueError = nullptr;
|
|
// CHECK: void* _ctx = nullptr;
|
|
// CHECK: auto returnValue = _impl::$s9Functions31throwFunctionWithPossibleReturnyS2iKF(a, _ctx, &opaqueError);
|
|
// CHECK: if (opaqueError != nullptr)
|
|
// CHECK: #ifdef __cpp_exceptions
|
|
// CHECK: throw (Swift::Error(opaqueError));
|
|
// CHECK: #else
|
|
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
|
|
// CHECK: #endif
|
|
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
|
|
// CHECK: }
|
|
|
|
@_expose(Cxx)
|
|
public func throwFunctionWithReturn() throws -> Int {
|
|
print("passThrowFunctionWithReturn")
|
|
throw NaiveErrors.returnError
|
|
return 0
|
|
}
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<swift::Int> throwFunctionWithReturn() SWIFT_SYMBOL("s:9Functions23throwFunctionWithReturnSiyKF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK: void* opaqueError = nullptr;
|
|
// CHECK: void* _ctx = nullptr;
|
|
// CHECK: auto returnValue = _impl::$s9Functions23throwFunctionWithReturnSiyKF(_ctx, &opaqueError);
|
|
// CHECK: #ifdef __cpp_exceptions
|
|
// CHECK: throw (Swift::Error(opaqueError));
|
|
// CHECK: #else
|
|
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
|
|
// CHECK: #endif
|
|
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
|
|
// CHECK: }
|