|
| 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