1
1
2
2
// REQUIRES: swift_swift_parser
3
3
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
5
6
6
7
// FIXME swift-ci linux tests do not support std::span
7
8
// UNSUPPORTED: OS=linux-gnu
@@ -32,6 +33,13 @@ struct X {
32
33
func myFunc5( ) -> SpanOfInt { }
33
34
}
34
35
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
+
35
43
// CHECK: @_alwaysEmitIntoClient @lifetime(copy span)
36
44
// CHECK-NEXT: func myFunc(_ span: Span<CInt>) -> Span<CInt> {
37
45
// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc(SpanOfInt(span))), copying: ())
@@ -56,3 +64,14 @@ struct X {
56
64
// CHECK-NEXT: func myFunc5() -> Span<CInt> {
57
65
// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc5()), copying: ())
58
66
// 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