Skip to content

Commit 57ef618

Browse files
committed
Don't enable SymbolLinkageMarkers, mark @_alwaysEmitIntoClient
1 parent 20ad631 commit 57ef618

31 files changed

+77
-55
lines changed

lib/Macros/Sources/SwiftMacros/PointerBoundsMacro.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,13 @@ public struct PointerBoundsMacro: PeerMacro {
600600
.with(\.attributes, funcDecl.attributes.filter { e in
601601
switch e {
602602
case .attribute(let attr):
603-
// don't apply this macro recursively
603+
// don't apply this macro recursively, and avoid dupe _alwaysEmitIntoClient
604604
let name = attr.attributeName.as(IdentifierTypeSyntax.self)?.name.text
605-
return name == nil || name != "PointerBounds"
605+
return name == nil || (name != "PointerBounds" && name != "_alwaysEmitIntoClient")
606606
default: return true
607607
}
608-
})
608+
} + [.attribute(AttributeSyntax(atSign: .atSignToken(),
609+
attributeName: IdentifierTypeSyntax(name: "_alwaysEmitIntoClient")))])
609610
return [DeclSyntax(newFunc)]
610611
} catch let error as DiagnosticError {
611612
context.diagnose(Diagnostic(node: error.node, message: MacroExpansionErrorMessage(error.description),

test/Macros/PointerBounds/CountedBy/CountExpr.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

88
@PointerBounds(.countedBy(pointer: 1, count: "size * count"))
99
func myFunc(_ ptr: UnsafePointer<CInt>, _ size: CInt, _ count: CInt) {
1010
}
1111

12-
// CHECK: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ size: CInt, _ count: CInt) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ size: CInt, _ count: CInt) {
1314
// CHECK-NEXT: let _ptrCount: some BinaryInteger = size * count
1415
// CHECK-NEXT: if ptr.count < _ptrCount || _ptrCount < 0 {
1516
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>) {
1314
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!, ptr2.baseAddress!, CInt(exactly: ptr2.count)!)
1415
// CHECK-NEXT: }
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: UnsafeMutableBufferPointer<CInt>) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeMutableBufferPointer<CInt>) {
1314
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1415
// CHECK-NEXT: }
1516

test/Macros/PointerBounds/CountedBy/MutableSpan.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: MutableSpan<CInt>) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: MutableSpan<CInt>) {
1314
// CHECK-NEXT: ptr.withUnsafeBufferPointer { _ptrPtr in
1415
// CHECK-NEXT: myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
1516
// CHECK-NEXT: }
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: UnsafeBufferPointer<CInt>?) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>?) {
1314
// CHECK-NEXT: myFunc(ptr?.baseAddress, CInt(exactly: ptr?.count ?? 0)!)
1415
// CHECK-NEXT: }
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

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

test/Macros/PointerBounds/CountedBy/SharedCount.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>, _ len: CInt) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>, _ ptr2: UnsafeBufferPointer<CInt>, _ len: CInt) {
1314
// CHECK-NEXT: let _ptrCount: some BinaryInteger = len
1415
// CHECK-NEXT: if ptr.count < _ptrCount || _ptrCount < 0 {
1516
// CHECK-NEXT: fatalError("bounds check failure when calling unsafe function")
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: UnsafeBufferPointer<CInt>) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: UnsafeBufferPointer<CInt>) {
1314
// CHECK-NEXT: myFunc(ptr.baseAddress!, CInt(exactly: ptr.count)!)
1415
// CHECK-NEXT: }

test/Macros/PointerBounds/CountedBy/SimpleSpan.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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 -enable-experimental-feature SymbolLinkageMarkers -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 %s
55

66
import _PointerBounds
77

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

12-
// CHECK: func myFunc(_ ptr: Span<CInt>) {
12+
// CHECK: @_alwaysEmitIntoClient
13+
// CHECK-NEXT: func myFunc(_ ptr: Span<CInt>) {
1314
// CHECK-NEXT: ptr.withUnsafeBufferPointer { _ptrPtr in
1415
// CHECK-NEXT: myFunc(_ptrPtr.baseAddress!, CInt(exactly: ptr.count)!)
1516
// CHECK-NEXT: }

0 commit comments

Comments
 (0)