mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Swiftify][StrictMemorySafety] Test `unsafe` warnings in wrappers (NFC) As _SwiftifyImport now emits the `unsafe` keyword to prevent warnings about unsafe code in the macro expansions, we should make sure that our tests do not emit any warnings. It turns out that calls to RawSpan::withUnsafeRawPointer are not recognised as unsafe, so we sometimes get warnings about using `unsafe` on a safe expression. This issue is tracked under rdar://145899513.
18 lines
885 B
Swift
18 lines
885 B
Swift
// REQUIRES: swift_swift_parser
|
|
|
|
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -strict-memory-safety -warnings-as-errors -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
|
|
|
|
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "size * count"))
|
|
func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
|
|
}
|
|
|
|
// CHECK: @_alwaysEmitIntoClient
|
|
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ size: CInt, _ count: CInt) {
|
|
// CHECK-NEXT: let _ptrCount: some BinaryInteger = size * count
|
|
// CHECK-NEXT: if ptr.count < _ptrCount || _ptrCount < 0 {
|
|
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
|
|
// CHECK-NEXT: }
|
|
// CHECK-NEXT: return unsafe myFunc(ptr.baseAddress!, size, count)
|
|
// CHECK-NEXT: }
|
|
|