11
22// REQUIRES: swift_swift_parser
33
4- // RUN: %target-swift-frontend %s -enable-experimental-cxx-interop -I %S/Inputs -Xcc -std=c++20 -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -verify -strict-memory-safety 2>&1 | %FileCheck --match-full-lines %s
4+ // FIXME: buggy sort order for return value transformation gives compilation error in expansion
5+ // RUN: not %target-swift-frontend %s -enable-experimental-cxx-interop -I %S/Inputs -Xcc -std=c++20 -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -verify -strict-memory-safety 2>&1 | %FileCheck --match-full-lines %s
56
67// FIXME swift-ci linux tests do not support std::span
78// UNSUPPORTED: OS=linux-gnu
@@ -32,6 +33,13 @@ struct X {
3233 func myFunc5( ) -> SpanOfInt { }
3334}
3435
36+ @_SwiftifyImport ( . lifetimeDependence( dependsOn: . param( 1 ) , pointer: . return, type: . copy) ,
37+ . sizedBy( pointer: . param( 2 ) , size: " count * size " ) ,
38+ . nonescaping( pointer: . param( 2 ) ) ,
39+ typeMappings: [ " SpanOfInt " : " std.span<CInt> " ] )
40+ func myFunc6( _ span: SpanOfInt , _ ptr: UnsafeRawPointer , _ count: CInt , _ size: CInt ) -> SpanOfInt {
41+ }
42+
3543// CHECK: @_alwaysEmitIntoClient @lifetime(copy span)
3644// CHECK-NEXT: func myFunc(_ span: Span<CInt>) -> Span<CInt> {
3745// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc(SpanOfInt(span))), copying: ())
@@ -56,3 +64,14 @@ struct X {
5664// CHECK-NEXT: func myFunc5() -> Span<CInt> {
5765// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc5()), copying: ())
5866// CHECK-NEXT: }
67+
68+ // CHECK: @_alwaysEmitIntoClient @lifetime(copy span)
69+ // CHECK-NEXT: func myFunc6(_ span: Span<CInt>, _ ptr: RawSpan, _ count: CInt, _ size: CInt) -> Span<CInt> {
70+ // CHECK-NEXT: let _ptrCount: some BinaryInteger = count * size
71+ // CHECK-NEXT: if ptr.byteCount < _ptrCount || _ptrCount < 0 {
72+ // CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
73+ // CHECK-NEXT: }
74+ // CHECK-NEXT: return unsafe ptr.withUnsafeBytes { _ptrPtr in
75+ // CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc6(SpanOfInt(span), _ptrPtr.baseAddress!, count, size)), copying: ())
76+ // CHECK-NEXT: }
77+ // CHECK-NEXT: }
0 commit comments