Skip to content

Commit 5b5f5dd

Browse files
committed
[Swiftify] Enable warnings-as-errors in interop test cases (NFC)
This enables -strict-memory-safety -warnings-as-errors on the Swift side to verify that the macro expansions don't cause any warnings and that they use `unsafe` correctly. On the clang side it enables -Xcc -Werror. To reduce noise in the test output and pass -Werror cleanly it also enables -Xcc -Wno-nullability-completeness. This will make it easier to detect mistakes when writing tests, because warnings stand out whereas previously they've been drowned out in the noise.
1 parent 711428d commit 5b5f5dd

File tree

7 files changed

+50
-49
lines changed

7 files changed

+50
-49
lines changed

test/Interop/C/swiftify-import/counted-by-lifetimebound.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
22
// REQUIRES: swift_feature_LifetimeDependence
33

4-
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByLifetimeboundClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
4+
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByLifetimeboundClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
55

66
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
77
// RUN: %empty-directory(%t)
8-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedByLifetimebound.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence %s
8+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedByLifetimebound.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
99

1010
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __sized_by __lifetimebound parameters and return values.
1111

@@ -92,5 +92,5 @@ public func callSimple(_ p: inout MutableSpan<CInt>) {
9292
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
9393
@inlinable
9494
public func callNoncountedLifetime(_ p: UnsafeMutablePointer<CInt>) {
95-
let _: MutableSpan<CInt> = noncountedLifetime(73, p)
95+
let _: MutableSpan<CInt> = unsafe noncountedLifetime(73, p)
9696
}

test/Interop/C/swiftify-import/counted-by-no-swiftify.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
22

33
// REQUIRES: swift_feature_SafeInteropWrappers
44

test/Interop/C/swiftify-import/counted-by-noescape.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
22
// REQUIRES: swift_feature_LifetimeDependence
33

4-
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByNoEscapeClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence | %FileCheck %s
4+
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByNoEscapeClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence -Xcc -Wno-nullability-completeness | %FileCheck %s
55

66
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
77
// RUN: %empty-directory(%t)
8-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedByNoEscape.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence %s
8+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedByNoEscape.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
99

1010
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __counted_by __noescape parameters.
1111

@@ -150,14 +150,14 @@ public func callNullable(_ p: inout MutableSpan<CInt>?) {
150150
@lifetime(p: copy p)
151151
@inlinable
152152
public func callReturnLifetimeBound(_ p: inout MutableSpan<CInt>) {
153-
let a: MutableSpan<CInt> = returnLifetimeBound(2, &p)
153+
let _: MutableSpan<CInt> = returnLifetimeBound(2, &p)
154154
}
155155

156156
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
157157
@inlinable
158158
public func callReturnPointer() {
159-
let a: UnsafeMutableBufferPointer<CInt>? = returnPointer(4) // call wrapper
160-
let b: UnsafeMutablePointer<CInt>? = returnPointer(4) // call unsafe interop
159+
let _: UnsafeMutableBufferPointer<CInt>? = returnPointer(4) // call wrapper
160+
let _: UnsafeMutablePointer<CInt>? = returnPointer(4) // call unsafe interop
161161
}
162162

163163
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
@@ -207,7 +207,7 @@ public func callFunc(_ p: inout MutableSpan<CInt>?) {
207207
@lifetime(p: copy p)
208208
@inlinable
209209
public func callFuncRenameKeyword(_ p: inout MutableSpan<CInt>?) {
210-
funcRenamed(func: &p, extension: 1, init: 2, open: 3, var: 4, is: 5, as: 6, in: 7, guard: 8, where: 9)
210+
let _ = funcRenamed(func: &p, extension: 1, init: 2, open: 3, var: 4, is: 5, as: 6, in: 7, guard: 8, where: 9)
211211
}
212212

213213
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)

test/Interop/C/swiftify-import/counted-by.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
22

3-
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=CountedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
44

55
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
66
// RUN: %empty-directory(%t)
7-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedBy.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s
7+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/CountedBy.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
88

99
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __counted_by parameters.
1010

@@ -67,73 +67,73 @@ import CountedByClang
6767

6868
@inlinable
6969
public func callComplexExpr(_ p: UnsafeMutableBufferPointer<CInt>) {
70-
complexExpr(CInt(p.count), 1, p)
70+
unsafe complexExpr(CInt(p.count), 1, p)
7171
}
7272

7373
@inlinable
7474
public func callConstInt(_ p: UnsafeMutableBufferPointer<CInt>) {
75-
constInt(p)
75+
unsafe constInt(p)
7676
}
7777

7878
@inlinable
7979
public func callNonnull(_ p: UnsafeMutableBufferPointer<CInt>) {
80-
nonnull(p)
80+
unsafe nonnull(p)
8181
}
8282

8383
@inlinable
8484
public func callNullUnspecified(_ p: UnsafeMutableBufferPointer<CInt>) {
85-
nullUnspecified(p)
85+
unsafe nullUnspecified(p)
8686
}
8787

8888
@inlinable
8989
public func callNullable(_ p: UnsafeMutableBufferPointer<CInt>?) {
90-
nullable(p)
90+
unsafe nullable(p)
9191
}
9292

9393
@inlinable
9494
public func callOffByOne(_ p: UnsafeMutableBufferPointer<CInt>) {
95-
offByOne(0, p)
95+
unsafe offByOne(0, p)
9696
}
9797

9898
@inlinable
9999
public func callReturnPointer() {
100-
let a: UnsafeMutableBufferPointer<CInt>? = returnPointer(4) // call wrapper
101-
let b: UnsafeMutablePointer<CInt>? = returnPointer(4) // call unsafe interop
100+
let _: UnsafeMutableBufferPointer<CInt>? = returnPointer(4) // call wrapper
101+
let _: UnsafeMutablePointer<CInt>? = returnPointer(4) // call unsafe interop
102102
}
103103

104104
@inlinable
105105
public func callScalar(_ p: UnsafeMutableBufferPointer<CInt>) {
106-
scalar(4, 2, p)
106+
unsafe scalar(4, 2, p)
107107
}
108108

109109
@inlinable
110110
public func callShared(_ p: UnsafeMutableBufferPointer<CInt>, _ p2: UnsafeMutableBufferPointer<CInt>) {
111-
shared(p, p2)
111+
unsafe shared(p, p2)
112112
}
113113

114114
@inlinable
115115
public func callSimple(_ p: UnsafeMutableBufferPointer<CInt>) {
116-
simple(p)
116+
unsafe simple(p)
117117
}
118118

119119
@inlinable
120120
public func callSimpleIndirectOriginal(_ p: UnsafeMutablePointer<CInt>) {
121-
let f = simple
122-
f(13, p)
121+
let f = unsafe simple
122+
unsafe f(13, p)
123123
}
124124

125125
@inlinable
126126
public func callSimpleIndirectOverload(_ p: UnsafeMutableBufferPointer<CInt>) {
127-
let f: (UnsafeMutableBufferPointer<CInt>) -> Void = simple
128-
f(p)
127+
let f: (UnsafeMutableBufferPointer<CInt>) -> Void = unsafe simple
128+
unsafe f(p)
129129
}
130130

131131
@inlinable
132132
public func callSimpleFlipped(_ p: UnsafeMutableBufferPointer<CInt>) {
133-
simpleFlipped(p)
133+
unsafe simpleFlipped(p)
134134
}
135135

136136
@inlinable
137137
public func callSwiftAttr(_ p: UnsafeMutableBufferPointer<CInt>) {
138-
swiftAttr(p)
138+
unsafe swiftAttr(p)
139139
}

test/Interop/C/swiftify-import/sized-by-lifetimebound.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
22
// REQUIRES: swift_feature_LifetimeDependence
33

4-
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByLifetimeboundClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
4+
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByLifetimeboundClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
55

66
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
77
// RUN: %empty-directory(%t)
8-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/SizedByLifetimebound.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence %s
8+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/SizedByLifetimebound.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -enable-experimental-feature LifetimeDependence -strict-memory-safety -warnings-as-errors -Xcc -Werror -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
99

1010
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __sized_by __lifetimebound parameters and return values.
1111

@@ -102,7 +102,7 @@ public func callSimple(_ p: RawSpan) {
102102
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
103103
@inlinable
104104
public func callNonsizedLifetime(_ p: UnsafeRawPointer) {
105-
let _: RawSpan = nonsizedLifetime(73, p)
105+
let _: RawSpan = unsafe nonsizedLifetime(73, p)
106106
}
107107

108108
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)

test/Interop/C/swiftify-import/sized-by-noescape.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
2+
// REQUIRES: swift_feature_LifetimeDependence
23

3-
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByNoEscapeClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
4+
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByNoEscapeClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature LifetimeDependence -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
45

56
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
67
// RUN: %empty-directory(%t)
7-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/SizedByNoEscape.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s
8+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/SizedByNoEscape.swiftmodule -I %S/Inputs -enable-experimental-feature LifetimeDependence -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
89

910
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __sized_by __noescape parameters.
1011
import SizedByNoEscapeClang
@@ -81,8 +82,8 @@ public func callNullable(_ p: RawSpan?) {
8182
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
8283
@inlinable
8384
public func callReturnPointer() {
84-
let a: UnsafeRawBufferPointer? = returnPointer(4) // call wrapper
85-
let b: UnsafeRawPointer? = returnPointer(4) // call unsafe interop
85+
let _: UnsafeRawBufferPointer? = returnPointer(4) // call wrapper
86+
let _: UnsafeRawPointer? = returnPointer(4) // call unsafe interop
8687
}
8788

8889
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)

test/Interop/C/swiftify-import/sized-by.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// REQUIRES: swift_feature_SafeInteropWrappers
22

3-
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=SizedByClang -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers -Xcc -Wno-nullability-completeness | %FileCheck %s
44

55
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well
6-
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s
6+
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -I %S/Inputs -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror -Xcc -Wno-nullability-completeness %s
77

88
// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __sized_by parameters.
99
import SizedByClang
@@ -44,53 +44,53 @@ import SizedByClang
4444

4545
@inlinable
4646
public func callComplexExpr(_ p: UnsafeMutableRawBufferPointer) {
47-
complexExpr(CInt(p.count), 1, p)
47+
unsafe complexExpr(CInt(p.count), 1, p)
4848
}
4949

5050
@inlinable
5151
public func callNonnull(_ p: UnsafeMutableRawBufferPointer) {
52-
nonnull(p)
52+
unsafe nonnull(p)
5353
}
5454

5555
@inlinable
5656
public func callNullUnspecified(_ p: UnsafeMutableRawBufferPointer) {
57-
nullUnspecified(p)
57+
unsafe nullUnspecified(p)
5858
}
5959

6060
@inlinable
6161
public func callNullable(_ p: UnsafeMutableRawBufferPointer?) {
62-
nullable(p)
62+
unsafe nullable(p)
6363
}
6464

6565
@inlinable
6666
public func callOpaque(_ p: UnsafeRawBufferPointer) {
67-
opaque(p)
67+
unsafe opaque(p)
6868
}
6969

7070
@inlinable
7171
public func callReturnPointer() {
72-
let a: UnsafeMutableRawBufferPointer? = returnPointer(4) // call wrapper
73-
let b: UnsafeMutableRawPointer? = returnPointer(4) // call unsafe interop
72+
let _: UnsafeMutableRawBufferPointer? = returnPointer(4) // call wrapper
73+
let _: UnsafeMutableRawPointer? = returnPointer(4) // call unsafe interop
7474
}
7575

7676
@inlinable
7777
public func callShared(_ p: UnsafeMutableRawBufferPointer, _ p2: UnsafeMutableRawBufferPointer) {
78-
shared(p, p2)
78+
unsafe shared(p, p2)
7979
}
8080

8181
@inlinable
8282
public func callSimple(_ p: UnsafeMutableRawBufferPointer) {
83-
simple(p)
83+
unsafe simple(p)
8484
}
8585

8686
@inlinable
8787
public func callSwiftAttr(_ p: UnsafeMutableRawBufferPointer) {
88-
swiftAttr(p)
88+
unsafe swiftAttr(p)
8989
}
9090

9191
@inlinable
9292
public func callCharsized(_ p: UnsafeMutableRawBufferPointer) {
93-
charsized(p)
93+
unsafe charsized(p)
9494
}
9595

9696
@inlinable

0 commit comments

Comments
 (0)