|
1 | 1 |
|
2 | 2 | // REQUIRES: swift_swift_parser
|
3 | 3 |
|
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 |
| 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 |
6 | 5 |
|
7 | 6 | // FIXME swift-ci linux tests do not support std::span
|
8 | 7 | // UNSUPPORTED: OS=linux-gnu
|
@@ -40,6 +39,20 @@ struct X {
|
40 | 39 | func myFunc6(_ span: SpanOfInt, _ ptr: UnsafeRawPointer, _ count: CInt, _ size: CInt) -> SpanOfInt {
|
41 | 40 | }
|
42 | 41 |
|
| 42 | +@_SwiftifyImport(.sizedBy(pointer: .param(2), size: "count * size"), |
| 43 | + .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy), |
| 44 | + .nonescaping(pointer: .param(2)), |
| 45 | + typeMappings: ["SpanOfInt" : "std.span<CInt>"]) |
| 46 | +func myFunc7(_ span: SpanOfInt, _ ptr: UnsafeRawPointer, _ count: CInt, _ size: CInt) -> SpanOfInt { |
| 47 | +} |
| 48 | + |
| 49 | +@_SwiftifyImport(.sizedBy(pointer: .param(1), size: "count * size"), |
| 50 | + .nonescaping(pointer: .param(1)), |
| 51 | + .lifetimeDependence(dependsOn: .param(2), pointer: .return, type: .copy), |
| 52 | + typeMappings: ["SpanOfInt" : "std.span<CInt>"]) |
| 53 | +func myFunc8(_ ptr: UnsafeRawPointer, _ span: SpanOfInt, _ count: CInt, _ size: CInt) -> SpanOfInt { |
| 54 | +} |
| 55 | + |
43 | 56 | // CHECK: @_alwaysEmitIntoClient @lifetime(copy span)
|
44 | 57 | // CHECK-NEXT: func myFunc(_ span: Span<CInt>) -> Span<CInt> {
|
45 | 58 | // CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: myFunc(SpanOfInt(span))), copying: ())
|
@@ -71,7 +84,29 @@ func myFunc6(_ span: SpanOfInt, _ ptr: UnsafeRawPointer, _ count: CInt, _ size:
|
71 | 84 | // CHECK-NEXT: if ptr.byteCount < _ptrCount || _ptrCount < 0 {
|
72 | 85 | // CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
|
73 | 86 | // 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: ()) |
| 87 | +// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: ptr.withUnsafeBytes { _ptrPtr in |
| 88 | +// CHECK-NEXT: return unsafe myFunc6(SpanOfInt(span), _ptrPtr.baseAddress!, count, size) |
| 89 | +// CHECK-NEXT: }), copying: ()) |
| 90 | +// CHECK-NEXT: } |
| 91 | + |
| 92 | +// CHECK: @_alwaysEmitIntoClient @lifetime(copy span) |
| 93 | +// CHECK-NEXT: func myFunc7(_ span: Span<CInt>, _ ptr: RawSpan, _ count: CInt, _ size: CInt) -> Span<CInt> { |
| 94 | +// CHECK-NEXT: let _ptrCount: some BinaryInteger = count * size |
| 95 | +// CHECK-NEXT: if ptr.byteCount < _ptrCount || _ptrCount < 0 { |
| 96 | +// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function") |
| 97 | +// CHECK-NEXT: } |
| 98 | +// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: ptr.withUnsafeBytes { _ptrPtr in |
| 99 | +// CHECK-NEXT: return unsafe myFunc7(SpanOfInt(span), _ptrPtr.baseAddress!, count, size) |
| 100 | +// CHECK-NEXT: }), copying: ()) |
| 101 | +// CHECK-NEXT: } |
| 102 | + |
| 103 | +// CHECK: @_alwaysEmitIntoClient @lifetime(copy span) |
| 104 | +// CHECK-NEXT: func myFunc8(_ ptr: RawSpan, _ span: Span<CInt>, _ count: CInt, _ size: CInt) -> Span<CInt> { |
| 105 | +// CHECK-NEXT: let _ptrCount: some BinaryInteger = count * size |
| 106 | +// CHECK-NEXT: if ptr.byteCount < _ptrCount || _ptrCount < 0 { |
| 107 | +// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function") |
76 | 108 | // CHECK-NEXT: }
|
| 109 | +// CHECK-NEXT: return unsafe _cxxOverrideLifetime(Span(_unsafeCxxSpan: ptr.withUnsafeBytes { _ptrPtr in |
| 110 | +// CHECK-NEXT: return unsafe myFunc8(_ptrPtr.baseAddress!, SpanOfInt(span), count, size) |
| 111 | +// CHECK-NEXT: }), copying: ()) |
77 | 112 | // CHECK-NEXT: }
|
0 commit comments