Skip to content

Commit d766d93

Browse files
committed
Handle FQTNs, always emit return even with Void-return type
1 parent 80b1d92 commit d766d93

25 files changed

+107
-73
lines changed

lib/Macros/Sources/SwiftMacros/PointerBoundsMacro.swift

+38-28
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,45 @@ enum UnsafePointerKind {
9393
case Mutable
9494
}
9595

96+
func getTypeName(_ type: TypeSyntax) throws -> TokenSyntax {
97+
switch type.kind {
98+
case .memberType:
99+
let memberType = type.as(MemberTypeSyntax.self)!
100+
if !memberType.baseType.isSwiftCoreModule {
101+
throw DiagnosticError("expected pointer type in Swift core module, got type \(type) with base type \(memberType.baseType)", node: type)
102+
}
103+
return memberType.name
104+
case .identifierType:
105+
return type.as(IdentifierTypeSyntax.self)!.name
106+
default:
107+
throw DiagnosticError("expected pointer type, got \(type) with kind \(type.kind)", node: type)
108+
}
109+
}
110+
111+
func replaceTypeName(_ type: TypeSyntax, _ name: TokenSyntax) -> TypeSyntax {
112+
if let memberType = type.as(MemberTypeSyntax.self) {
113+
return TypeSyntax(memberType.with(\.name, name))
114+
}
115+
let idType = type.as(IdentifierTypeSyntax.self)!
116+
return TypeSyntax(idType.with(\.name, name))
117+
}
118+
96119
func transformType(_ prev: TypeSyntax, _ variant: Variant, _ isSizedBy: Bool) throws -> TypeSyntax {
97120
if let optType = prev.as(OptionalTypeSyntax.self) {
98121
return TypeSyntax(optType.with(\.wrappedType, try transformType(optType.wrappedType, variant, isSizedBy)))
99122
}
100123
if let impOptType = prev.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) {
101124
return try transformType(impOptType.wrappedType, variant, isSizedBy)
102125
}
103-
guard let idType = prev.as(IdentifierTypeSyntax.self) else {
104-
throw DiagnosticError("expected pointer type, got \(prev) with kind \(prev.kind)", node: prev)
105-
}
106-
let text = idType.name.text
126+
let name = try getTypeName(prev)
127+
let text = name.text
107128
let kind: UnsafePointerKind = switch text {
108129
case "UnsafePointer": .Immutable
109130
case "UnsafeMutablePointer": .Mutable
110131
case "UnsafeRawPointer": .Immutable
111132
case "UnsafeMutableRawPointer": .Mutable
112133
default: throw DiagnosticError("expected Unsafe[Mutable][Raw]Pointer type for type \(prev)" +
113-
" - first type token is '\(text)'", node: idType.name)
134+
" - first type token is '\(text)'", node: name)
114135
}
115136
if isSizedBy {
116137
let token: TokenSyntax = switch (kind, variant.generateSpan) {
@@ -122,15 +143,15 @@ func transformType(_ prev: TypeSyntax, _ variant: Variant, _ isSizedBy: Bool) th
122143
return TypeSyntax(IdentifierTypeSyntax(name: token))
123144
}
124145
if text == "UnsafeRawPointer" || text == "UnsafeMutableRawPointer" {
125-
throw DiagnosticError("raw pointers only supported for SizedBy", node: idType.name)
146+
throw DiagnosticError("raw pointers only supported for SizedBy", node: name)
126147
}
127148
let token: TokenSyntax = switch (kind, variant.generateSpan) {
128149
case (.Immutable, true): "Span"
129150
case (.Mutable, true): "MutableSpan"
130151
case (.Immutable, false): "UnsafeBufferPointer"
131152
case (.Mutable, false): "UnsafeMutableBufferPointer"
132153
}
133-
return TypeSyntax(idType.with(\.name, token))
154+
return replaceTypeName(prev, token)
134155
}
135156

136157
struct Variant {
@@ -209,11 +230,6 @@ struct FunctionCallBuilder: BoundsCheckedThunkBuilder {
209230
}
210231
}
211232

212-
func hasReturnType(_ signature: FunctionSignatureSyntax) -> Bool {
213-
let returnType = signature.returnClause?.type.as(IdentifierTypeSyntax.self)?.name.text ?? "Void"
214-
return returnType != "Void"
215-
}
216-
217233
protocol PointerBoundsThunkBuilder: BoundsCheckedThunkBuilder {
218234
var name: TokenSyntax { get }
219235
var nullable: Bool { get }
@@ -274,8 +290,7 @@ struct CountedOrSizedPointerThunkBuilder: PointerBoundsThunkBuilder {
274290
}
275291

276292
func castIntToTargetType(expr: ExprSyntax, type: TypeSyntax) -> ExprSyntax {
277-
let idType = type.as(IdentifierTypeSyntax.self)!
278-
if idType.name.text == "Int" {
293+
if type.isSwiftInt {
279294
return expr
280295
}
281296
return ExprSyntax("\(type)(exactly: \(expr))!")
@@ -290,15 +305,10 @@ struct CountedOrSizedPointerThunkBuilder: PointerBoundsThunkBuilder {
290305
let call = try base.buildFunctionCall(args, variant)
291306
let ptrRef = unwrapIfNullable(ExprSyntax(DeclReferenceExprSyntax(baseName: name)))
292307

293-
let returnKw: String = if hasReturnType(signature) {
294-
"return "
295-
} else {
296-
""
297-
}
298308
let funcName = isSizedBy ? "withUnsafeBytes" : "withUnsafeBufferPointer"
299309
let unwrappedCall = ExprSyntax("""
300310
\(ptrRef).\(raw: funcName) { \(unwrappedName) in
301-
\(raw: returnKw)\(call)
311+
return \(call)
302312
}
303313
""")
304314
return unwrappedCall
@@ -419,7 +429,7 @@ public struct PointerBoundsMacro: PeerMacro {
419429
guard let intLiteral = expr.as(IntegerLiteralExprSyntax.self) else {
420430
throw DiagnosticError("expected integer literal, got '\(expr)'", node: expr)
421431
}
422-
guard let res = Int(intLiteral.literal.text) else {
432+
guard let res = intLiteral.representedLiteralValue else {
423433
throw DiagnosticError("expected integer literal, got '\(expr)'", node: expr)
424434
}
425435
return res
@@ -429,10 +439,14 @@ public struct PointerBoundsMacro: PeerMacro {
429439
guard let boolLiteral = expr.as(BooleanLiteralExprSyntax.self) else {
430440
throw DiagnosticError("expected boolean literal, got '\(expr)'", node: expr)
431441
}
432-
guard let res = Bool(boolLiteral.literal.text) else {
442+
switch boolLiteral.literal.tokenKind {
443+
case .keyword(.true):
444+
return true
445+
case .keyword(.false):
446+
return false
447+
default:
433448
throw DiagnosticError("expected bool literal, got '\(expr)'", node: expr)
434449
}
435-
return res
436450
}
437451

438452
static func parseCountedByEnum(_ enumConstructorExpr: FunctionCallExprSyntax, _ signature: FunctionSignatureSyntax) throws -> ParamInfo {
@@ -590,12 +604,8 @@ public struct PointerBoundsMacro: PeerMacro {
590604
CodeBlockItemSyntax(leadingTrivia: "\n", item: e)
591605
}
592606
}
593-
let call = if hasReturnType(funcDecl.signature) {
594-
CodeBlockItemSyntax(item: CodeBlockItemSyntax.Item(ReturnStmtSyntax(returnKeyword: .keyword(.return, trailingTrivia: " "),
607+
let call = CodeBlockItemSyntax(item: CodeBlockItemSyntax.Item(ReturnStmtSyntax(returnKeyword: .keyword(.return, trailingTrivia: " "),
595608
expression: try builder.buildFunctionCall([:], variant))))
596-
} else {
597-
CodeBlockItemSyntax(item: CodeBlockItemSyntax.Item(try builder.buildFunctionCall([:], variant)))
598-
}
599609
let body = CodeBlockSyntax(statements: CodeBlockItemListSyntax(checks + [call]))
600610
let newFunc = funcDecl
601611
.with(\.signature, newSignature)

test/Macros/PointerBounds/CountedBy/CountExpr.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "size * count"))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
@@ -13,6 +13,6 @@ func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
1313
// CHECK-NEXT: if ptr.count < _ptrCount || _ptrCount < 0 {
1414
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
1515
// CHECK-NEXT: }
16-
// CHECK-NEXT: myFunc(ptr.baseAddress!, size, count)
16+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, size, count)
1717
// CHECK-NEXT: }
1818

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 3, count: "len2"))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt, _ ptr2: UnsafePointer<CInt>, _ len2: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!, ptr2.baseAddress!, CInt(exactly: ptr2.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!, ptr2.baseAddress!, CInt(exactly: ptr2.count)!)
1313
// CHECK-NEXT: }
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"))
77
func myFunc(_ ptr: UnsafeMutablePointer<CInt>, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeMutableBufferPointer<CInt>) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1313
// CHECK-NEXT: }
1414

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
77
func myFunc(_ ptr: UnsafeMutablePointer<CInt>, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: MutableSpan<CInt>) {
12-
// CHECK-NEXT: ptr.withUnsafeBufferPointer { _ptrPtr in
13-
// CHECK-NEXT: myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return ptr.withUnsafeBufferPointer { _ptrPtr in
13+
// CHECK-NEXT: return myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
1414
// CHECK-NEXT: }
1515
// CHECK-NEXT: }
1616

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"))
77
func myFunc(_ ptr: UnsafePointer<CInt>?, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>?) {
12-
// CHECK-NEXT: myFunc(ptr?.baseAddress, CInt(exactly: ptr?.count ?? 0)!)
12+
// CHECK-NEXT: return myFunc(ptr?.baseAddress, CInt(exactly: ptr?.count ?? 0)!)
1313
// CHECK-NEXT: }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: swift_swift_parser
2+
// REQUIRES: pointer_bounds
3+
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
5+
6+
@PointerBounds(.countedBy(pointer: 1, count: "len"))
7+
func foo(_ ptr: Swift.UnsafePointer<Swift.Int>, _ len: Swift.Int) -> Swift.Void {
8+
}
9+
10+
@PointerBounds(.countedBy(pointer: 1, count: "len"))
11+
func bar(_ ptr: Swift.UnsafePointer<Swift.CInt>, _ len: Swift.Int) -> () {
12+
}
13+
14+
// CHECK: @_alwaysEmitIntoClient
15+
// CHECK-NEXT: func foo(_ ptr: Swift.UnsafeBufferPointer<Swift.Int>) -> Swift.Void {
16+
// CHECK-NEXT: return foo(ptr.baseAddress!, ptr.count)
17+
// CHECK-NEXT: }
18+
19+
// CHECK: @_alwaysEmitIntoClient
20+
// CHECK-NEXT: func bar(_ ptr: Swift.UnsafeBufferPointer<Swift.CInt>) -> () {
21+
// CHECK-NEXT: return bar(ptr.baseAddress!, ptr.count)
22+
// CHECK-NEXT: }
23+
24+

test/Macros/PointerBounds/CountedBy/Return.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) -> CInt {

test/Macros/PointerBounds/CountedBy/SharedCount.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"), .countedBy(pointer: 2, count: "len"))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ ptr2: UnsafePointer<CInt>, _ len: CInt) {
@@ -17,5 +17,5 @@ func myFunc(_ ptr: UnsafePointer<CInt>, _ ptr2: UnsafePointer<CInt>, _ len: CInt
1717
// CHECK-NEXT: if ptr2.count < _ptr2Count || _ptr2Count < 0 {
1818
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
1919
// CHECK-NEXT: }
20-
// CHECK-NEXT: myFunc(ptr.baseAddress!, ptr2.baseAddress!, len)
20+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, ptr2.baseAddress!, len)
2121
// CHECK-NEXT: }
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1313
// CHECK-NEXT: }
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: Span<CInt>) {
12-
// CHECK-NEXT: ptr.withUnsafeBufferPointer { _ptrPtr in
13-
// CHECK-NEXT: myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return ptr.withUnsafeBufferPointer { _ptrPtr in
13+
// CHECK-NEXT: return myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
1414
// CHECK-NEXT: }
1515
// CHECK-NEXT: }

test/Macros/PointerBounds/CountedBy/SimpleSpanWithReturn.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"), .nonescaping(pointer: 1))
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) -> CInt {
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.countedBy(pointer: 1, count: "len"))
77
func myFunc(_ ptr: UnsafePointer<CInt>!, _ len: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1313
// CHECK-NEXT: }
1414

test/Macros/PointerBounds/MacroErrors/UnexpectedCountType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// XFAIL: *
55

6-
// RUN: not %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
6+
// RUN: not %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
77
// RUN: %target-typecheck-verify-swift %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -verify
88

99
@PointerBounds(.countedBy(pointer: 1, count: "len"))
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.sizedBy(pointer: 1, size: "size"), .sizedBy(pointer: 3, size: "size2"))
77
func myFunc(_ ptr: UnsafeRawPointer, _ size: CInt, _ ptr2: UnsafeRawPointer, _ size2: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeRawBufferPointer, _ ptr2: UnsafeRawBufferPointer) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!, ptr2.baseAddress!, CInt(exactly: ptr2.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!, ptr2.baseAddress!, CInt(exactly: ptr2.count)!)
1313
// CHECK-NEXT: }
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// REQUIRES: swift_swift_parser
22
// REQUIRES: pointer_bounds
33

4-
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions 2>&1 | %FileCheck --match-full-lines %s
55

66
@PointerBounds(.sizedBy(pointer: 1, size: "size"))
77
func myFunc(_ ptr: UnsafeMutableRawPointer, _ size: CInt) {
88
}
99

1010
// CHECK: @_alwaysEmitIntoClient
1111
// CHECK-NEXT: func myFunc(_ ptr: UnsafeMutableRawBufferPointer) {
12-
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
12+
// CHECK-NEXT: return myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1313
// CHECK-NEXT: }

0 commit comments

Comments
 (0)