|
| 1 | +// REQUIRES: swift_feature_SafeInteropWrappers |
| 2 | + |
| 3 | +// RUN: %empty-directory(%t) |
| 4 | +// RUN: split-file %s %t |
| 5 | + |
| 6 | +// RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -verify |
| 7 | +// RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -dump-macro-expansions 2>&1 | %FileCheck --dry-run > %t/macro-expansions.out |
| 8 | +// RUN: %diff %t/macro-expansions.out %t/macro-expansions.expected |
| 9 | +// RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -o %t/test.swiftmodule -I %t -import-objc-header %t/bridging.h -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness -Xcc -Wno-div-by-zero -Xcc -Wno-pointer-to-int-cast %t/test.swift -dump-source-file-imports 2>&1 | %FileCheck --dry-run > %t/imports.out |
| 10 | +// RUN: %diff %t/imports.out %t/imports.expected |
| 11 | + |
| 12 | +//--- imports.expected |
| 13 | +imports for TMP_DIR/test.swift: |
| 14 | + Swift |
| 15 | + __ObjC |
| 16 | + _StringProcessing |
| 17 | + _SwiftConcurrencyShims |
| 18 | + _Concurrency |
| 19 | +imports for __ObjC.foo: |
| 20 | +imports for @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift: |
| 21 | + __ObjC |
| 22 | + Swift |
| 23 | + |
| 24 | +//--- macro-expansions.expected |
| 25 | +@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift |
| 26 | +------------------------------ |
| 27 | +/// This is an auto-generated wrapper for safer interop |
| 28 | +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_disfavoredOverload public func foo(_ p: Span<Int32>) { |
| 29 | + let len = Int32(exactly: p.count)! |
| 30 | + return unsafe p.withUnsafeBufferPointer { _pPtr in |
| 31 | + return unsafe foo(len, _pPtr.baseAddress!) |
| 32 | + } |
| 33 | +} |
| 34 | +------------------------------ |
| 35 | + |
| 36 | +//--- test.swift |
| 37 | +func test(s: Span<CInt>) { |
| 38 | + foo(s) |
| 39 | +} |
| 40 | + |
| 41 | +//--- bridging.h |
| 42 | +#include <ptrcheck.h> |
| 43 | +#include <lifetimebound.h> |
| 44 | + |
| 45 | +void foo(int len, const int * __counted_by(len) p __noescape); |
0 commit comments