Files
swift-mirror/test/Macros/SwiftifyImport/CountedBy/SharedCount.swift
Henrik G. Olsson 27a29c0baf [Swiftify][StrictMemorySafety] Test unsafe warnings in wrappers (NFC) (#79719)
[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.
2025-03-03 17:56:12 -08:00

21 lines
1.2 KiB
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: "len"), .countedBy(pointer: .param(2), count: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ ptr2: UnsafePointer<CInt>, _ len: CInt) {
}
// CHECK: @_alwaysEmitIntoClient
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>, _ len: CInt) {
// CHECK-NEXT: let _ptrCount: some BinaryInteger = len
// CHECK-NEXT: if ptr.count < _ptrCount || _ptrCount < 0 {
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
// CHECK-NEXT: }
// CHECK-NEXT: let _ptr2Count: some BinaryInteger = len
// CHECK-NEXT: if ptr2.count < _ptr2Count || _ptr2Count < 0 {
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
// CHECK-NEXT: }
// CHECK-NEXT: return unsafe myFunc(ptr.baseAddress!, ptr2.baseAddress!, len)
// CHECK-NEXT: }