Skip to content

Commit ebbf7b4

Browse files
committed
IRGen: Split hoisting tests out of weak_import_native.swift into a new test case.
Once the `CHECK-DAG` directives in `weak_import_native` were being recognized correctly, the `CHECK:` lines later in the test were interfering with `CHECK-DAG` matches because some of them straddled the existing `CHECK:` lines.
1 parent a562090 commit ebbf7b4

File tree

4 files changed

+107
-94
lines changed

4 files changed

+107
-94
lines changed

test/IRGen/Inputs/weak_import_native_helper.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,3 @@ extension ProtocolWithWeakMembers {
125125

126126
public protocol BaseP {}
127127
@_weakLinked extension S : BaseP {}
128-
129-
130-
public func getVersion() -> Int {
131-
// Used to return 0.
132-
return 1
133-
}
134-
135-
@_weakLinked public struct ResilientStruct {
136-
public init() {}
137-
138-
public func fn(_ x: Int) {}
139-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public enum E {
2+
case strong
3+
4+
@_weakLinked
5+
case weak
6+
}
7+
8+
public func getVersion() -> Int {
9+
// Used to return 0.
10+
return 1
11+
}
12+
13+
@_weakLinked public struct ResilientStruct {
14+
public init() {}
15+
16+
public func fn(_ x: Int) {}
17+
}

test/IRGen/weak_import_native.swift

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -182,85 +182,3 @@ protocol RefinesP : BaseP {}
182182

183183
// CHECK-DAG: @"$s25weak_import_native_helper1SVAA5BasePAAWP" = extern_weak global i8*
184184
extension S : RefinesP {}
185-
186-
// We should not hoist the metadata accessor accross the version check.
187-
188-
// CHECK-LABEL: define{{.*}} void @"$s18weak_import_native28test_not_hoist_weakly_linkedyyF"()
189-
// CHECK-NOT: 15ResilientStructVMa
190-
// CHECK: getVersion
191-
// CHECK: br
192-
// CHECK: 15ResilientStructVMa
193-
// CHECK: ret
194-
195-
public func test_not_hoist_weakly_linked() {
196-
if getVersion() == 1 {
197-
var _ = ResilientStruct()
198-
}
199-
}
200-
201-
// CHECK-LABEL: define{{.*}} void @"$s18weak_import_native29test_not_hoist_weakly_linked2yyF"()
202-
// CHECK-NOT: 15ResilientStructVMa
203-
// CHECK: getVersion
204-
// CHECK: br
205-
// CHECK: 15ResilientStructVMa
206-
// CHECK: ret
207-
public func test_not_hoist_weakly_linked2() {
208-
if getVersion() == 1 {
209-
var _ = (ResilientStruct(), 1)
210-
}
211-
}
212-
213-
struct One<T> {
214-
var elt : T?
215-
}
216-
217-
// CHECK-LABEL: define{{.*}} void @"$s18weak_import_native29test_not_hoist_weakly_linked3yyF"()
218-
// CHECK-NOT: 15ResilientStructVMa
219-
// CHECK: getVersion
220-
// CHECK: br
221-
// CHECK: 15ResilientStructVMa
222-
// CHECK: ret
223-
public func test_not_hoist_weakly_linked3() {
224-
if getVersion() == 1 {
225-
var _ = One(elt:ResilientStruct())
226-
}
227-
}
228-
229-
// CHECK-LABEL: define{{.*}} void @"$s18weak_import_native29test_not_hoist_weakly_linked4yyF"()
230-
// CHECK-NOT: 15ResilientStructVMa
231-
// CHECK: getVersion
232-
// CHECK: br
233-
// CHECK: 15ResilientStructVMa
234-
// CHECK: ret
235-
public func test_not_hoist_weakly_linked4() {
236-
if getVersion() == 1 {
237-
var _ = One(elt:(ResilientStruct(), 1))
238-
}
239-
}
240-
241-
// CHECK-LABEL: define{{.*}} @"$s18weak_import_native29test_weakly_linked_enum_cases1eSi0a1_b1_C7_helper1EO_t
242-
// CHECK: [[TAG:%.*]] = call i32 %getEnumTag(
243-
// CHECK: [[STRONG_CASE:%.*]] = load i32, i32* @"$s25weak_import_native_helper1EO6strongyA2CmFWC"
244-
// CHECK: [[IS_STRONG:%.*]] = icmp eq i32 [[TAG]], [[STRONG_CASE]]
245-
// CHECK: br i1 [[IS_STRONG]], label %[[BB0:[0-9]+]], label %[[BB1:[0-9]+]]
246-
//
247-
// CHECK: [[BB1]]:
248-
// CHECK: br i1 icmp eq ({{.*}} ptrtoint (i32* @"$s25weak_import_native_helper1EO0A0yA2CmFWC" to {{.*}}), {{.*}} 0), label %[[BB2:[0-9]+]], label %[[BB3:[0-9]+]]
249-
//
250-
// CHECK: [[BB3]]:
251-
// CHECK: [[WEAK_CASE:%.*]] = load i32, i32* @"$s25weak_import_native_helper1EO0A0yA2CmFWC"
252-
// CHECK: [[IS_WEAK:%.*]] = icmp eq i32 [[TAG]], [[WEAK_CASE]]
253-
// CHECK: br label %[[BB2]]
254-
//
255-
// CHECK: [[BB2]]:
256-
// CHECK: = phi i1 [ false, %[[BB1]] ], [ [[IS_WEAK]], %[[BB3]] ]
257-
public func test_weakly_linked_enum_cases(e: E) -> Int {
258-
switch e {
259-
case .strong:
260-
return 1
261-
case .weak:
262-
return 2
263-
default:
264-
return 3
265-
}
266-
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/weak_import_native_hoist_helper.swiftmodule -parse-as-library %S/Inputs/weak_import_native_hoist_helper.swift -enable-library-evolution
3+
//
4+
// RUN: %target-swift-frontend -disable-type-layout -primary-file %s -I %t -emit-ir | %FileCheck %s
5+
6+
// UNSUPPORTED: OS=windows-msvc
7+
8+
import weak_import_native_hoist_helper
9+
10+
// We should not hoist the metadata accessor accross the version check.
11+
12+
// CHECK-LABEL: define {{.*}} void @"$s24weak_import_native_hoist09test_not_D14_weakly_linkedyyF"()
13+
// CHECK-NOT: 15ResilientStructVMa
14+
// CHECK: getVersion
15+
// CHECK: br
16+
// CHECK: 15ResilientStructVMa
17+
// CHECK: ret
18+
19+
public func test_not_hoist_weakly_linked() {
20+
if getVersion() == 1 {
21+
var _ = ResilientStruct()
22+
}
23+
}
24+
25+
// CHECK-LABEL: define {{.*}} void @"$s24weak_import_native_hoist09test_not_D15_weakly_linked2yyF"()
26+
// CHECK-NOT: 15ResilientStructVMa
27+
// CHECK: getVersion
28+
// CHECK: br
29+
// CHECK: 15ResilientStructVMa
30+
// CHECK: ret
31+
public func test_not_hoist_weakly_linked2() {
32+
if getVersion() == 1 {
33+
var _ = (ResilientStruct(), 1)
34+
}
35+
}
36+
37+
struct One<T> {
38+
var elt : T?
39+
}
40+
41+
// CHECK-LABEL: define {{.*}} void @"$s24weak_import_native_hoist09test_not_D15_weakly_linked3yyF"()
42+
// CHECK-NOT: 15ResilientStructVMa
43+
// CHECK: getVersion
44+
// CHECK: br
45+
// CHECK: 15ResilientStructVMa
46+
// CHECK: ret
47+
public func test_not_hoist_weakly_linked3() {
48+
if getVersion() == 1 {
49+
var _ = One(elt:ResilientStruct())
50+
}
51+
}
52+
53+
// CHECK-LABEL: define {{.*}} void @"$s24weak_import_native_hoist09test_not_D15_weakly_linked4yyF"()
54+
// CHECK-NOT: 15ResilientStructVMa
55+
// CHECK: getVersion
56+
// CHECK: br
57+
// CHECK: 15ResilientStructVMa
58+
// CHECK: ret
59+
public func test_not_hoist_weakly_linked4() {
60+
if getVersion() == 1 {
61+
var _ = One(elt:(ResilientStruct(), 1))
62+
}
63+
}
64+
65+
// CHECK-LABEL: define {{.*}} @"$s24weak_import_native_hoist29test_weakly_linked_enum_cases1eSi0a1_b1_c1_D7_helper1EO_tF
66+
// CHECK: [[TAG:%.*]] = call i32 %getEnumTag(
67+
// CHECK: [[STRONG_CASE:%.*]] = load i32, i32* @"$s31weak_import_native_hoist_helper1EO6strongyA2CmFWC"
68+
// CHECK: [[IS_STRONG:%.*]] = icmp eq i32 [[TAG]], [[STRONG_CASE]]
69+
// CHECK: br i1 [[IS_STRONG]], label %[[BB0:[0-9]+]], label %[[BB1:[0-9]+]]
70+
//
71+
// CHECK: [[BB1]]:
72+
// CHECK: br i1 icmp eq ({{.*}} ptrtoint (i32* @"$s31weak_import_native_hoist_helper1EO0A0yA2CmFWC" to {{.*}}), {{.*}} 0), label %[[BB2:[0-9]+]], label %[[BB3:[0-9]+]]
73+
//
74+
// CHECK: [[BB3]]:
75+
// CHECK: [[WEAK_CASE:%.*]] = load i32, i32* @"$s31weak_import_native_hoist_helper1EO0A0yA2CmFWC"
76+
// CHECK: [[IS_WEAK:%.*]] = icmp eq i32 [[TAG]], [[WEAK_CASE]]
77+
// CHECK: br label %[[BB2]]
78+
//
79+
// CHECK: [[BB2]]:
80+
// CHECK: = phi i1 [ false, %[[BB1]] ], [ [[IS_WEAK]], %[[BB3]] ]
81+
public func test_weakly_linked_enum_cases(e: E) -> Int {
82+
switch e {
83+
case .strong:
84+
return 1
85+
case .weak:
86+
return 2
87+
default:
88+
return 3
89+
}
90+
}

0 commit comments

Comments
 (0)