Files
swift-mirror/test/Macros/SwiftifyImport/CountedBy/SimpleCount.swift
Henrik G. Olsson 2e01ba308f [Swiftify] Don't use unsafe for Unsafe[Mut][Raw]BufferPointer.count
Although the type is unsafe, the count is marked `@safe`, and this use
of `unsafe` results in a warning (regardless of whether strict memory
safety is enabled or not).
Keep emitting `unsafe` when the pointer buffer is wrapped in Optional
for now however, because that is currently flagged as unsafe.

rdar://162416566
2025-10-10 22:51:24 -07:00

14 lines
659 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: "len"))
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
}
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>) {
// CHECK-NEXT: let len = CInt(exactly: ptr.count)!
// CHECK-NEXT: return unsafe myFunc(ptr.baseAddress!, len)
// CHECK-NEXT: }