|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %t/src/main.swift \ |
| 5 | +// RUN: -import-bridging-header %t/src/test.h \ |
| 6 | +// RUN: -module-name main -I %t -emit-sil -serialize-diagnostics -serialize-diagnostics-path %t/test.diag | %FileCheck %s |
| 7 | + |
| 8 | +// RUN: c-index-test -read-diagnostics %t/test.diag 2>&1 | %FileCheck --check-prefix CHECK-DIAG %t/src/test.h |
| 9 | + |
| 10 | +//--- test.h |
| 11 | +#include <stdbool.h> |
| 12 | + |
| 13 | +#define MACRO_INT 42 |
| 14 | + |
| 15 | +const int const_int = 42; |
| 16 | +static int static_int = 42; |
| 17 | +static const int static_const_int = 42; |
| 18 | + |
| 19 | +static const bool static_const_bool = true; |
| 20 | +static const char static_const_char = 42; |
| 21 | +static const char static_const_char_with_long_literal = 42ull; |
| 22 | +static const char static_const_char_with_overflow_literal = 777ull; // CHECK-DIAG: [[@LINE]]:{{.*}}: warning: implicit conversion from 'unsigned long long' to 'char' changes value from 777 to 9 |
| 23 | +static const long static_const_long = 42; |
| 24 | +static const float static_const_float = 42.0; |
| 25 | +static const double static_const_double = 42.0; |
| 26 | + |
| 27 | +static const char static_const_char_array[4] = {1, 2, 3, 4}; |
| 28 | +static const char *static_const_pointer = 0; |
| 29 | + |
| 30 | +static const char static_const_char_referencing_other_const = 1 + static_const_char; |
| 31 | + |
| 32 | +typedef enum MyEnum: char { |
| 33 | + MyEnumCase0 = 0, MyEnumCase1, MyEnumCase2 |
| 34 | +} MyEnum; |
| 35 | +static const MyEnum static_const_enum = MyEnumCase1; |
| 36 | + |
| 37 | +struct MyStruct { |
| 38 | + int field; |
| 39 | +}; |
| 40 | +__attribute__((swift_name("MyStruct.static_const_int_as_a_member"))) |
| 41 | +static const int static_const_int_as_a_member = 42; |
| 42 | + |
| 43 | +typedef int ImportAsStruct __attribute__((swift_wrapper(struct))); |
| 44 | +static const ImportAsStruct ImportAsStructFoo = 123; |
| 45 | +typedef int ImportAsEnum __attribute__((swift_wrapper(enum))); |
| 46 | +static const ImportAsEnum ImportAsEnumFoo = 123; |
| 47 | + |
| 48 | +//--- main.swift |
| 49 | +func foo() { |
| 50 | + print(MACRO_INT) |
| 51 | + |
| 52 | + print(const_int) |
| 53 | + print(static_int) |
| 54 | + print(static_const_int) |
| 55 | + |
| 56 | + print(static_const_bool) |
| 57 | + print(static_const_char) |
| 58 | + print(static_const_char_with_long_literal) |
| 59 | + print(static_const_char_with_overflow_literal) |
| 60 | + print(static_const_long) |
| 61 | + print(static_const_float) |
| 62 | + print(static_const_double) |
| 63 | + |
| 64 | + print(static_const_char_array) |
| 65 | + print(static_const_pointer) |
| 66 | + |
| 67 | + print(static_const_char_referencing_other_const) |
| 68 | + |
| 69 | + print(static_const_enum) |
| 70 | + |
| 71 | + print(MyStruct.static_const_int_as_a_member) |
| 72 | + |
| 73 | + print(ImportAsStruct.foo) |
| 74 | + print(ImportAsEnum.foo) |
| 75 | +} |
| 76 | + |
| 77 | +// Globals that don't get their value imported stay as public_external: |
| 78 | +// CHECK: sil_global public_external @static_int : $Int32 |
| 79 | +// CHECK: sil_global public_external [let] @static_const_char_array : $(Int8, Int8, Int8, Int8) |
| 80 | +// CHECK: sil_global public_external @static_const_pointer : $Optional<UnsafePointer<Int8>> |
| 81 | + |
| 82 | +// CHECK: sil shared [transparent] @$sSC9MACRO_INTs5Int32Vvg : $@convention(thin) () -> Int32 { |
| 83 | +// CHECK-NEXT: bb0: |
| 84 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 85 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 86 | +// CHECK-NEXT: return %1 |
| 87 | +// CHECK-NEXT: } |
| 88 | + |
| 89 | +// CHECK: sil shared [transparent] @$sSo9const_ints5Int32Vvg : $@convention(thin) () -> Int32 { |
| 90 | +// CHECK-NEXT: bb0: |
| 91 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 92 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 93 | +// CHECK-NEXT: return %1 |
| 94 | +// CHECK-NEXT: } |
| 95 | + |
| 96 | +// CHECK: sil shared [transparent] @$sSo16static_const_ints5Int32Vvg : $@convention(thin) () -> Int32 { |
| 97 | +// CHECK-NEXT: bb0: |
| 98 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 99 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 100 | +// CHECK-NEXT: return %1 |
| 101 | +// CHECK-NEXT: } |
| 102 | + |
| 103 | +// CHECK: sil shared [transparent] @$sSo17static_const_boolSbvg : $@convention(thin) () -> Bool { |
| 104 | +// CHECK-NEXT: bb0: |
| 105 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1 |
| 106 | +// CHECK-NEXT: %1 = struct $Bool (%0) |
| 107 | +// CHECK-NEXT: return %1 |
| 108 | +// CHECK-NEXT: } |
| 109 | + |
| 110 | +// CHECK: sil shared [transparent] @$sSo17static_const_chars4Int8Vvg : $@convention(thin) () -> Int8 { |
| 111 | +// CHECK-NEXT: bb0: |
| 112 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 42 |
| 113 | +// CHECK-NEXT: %1 = struct $Int8 (%0) |
| 114 | +// CHECK-NEXT: return %1 |
| 115 | +// CHECK-NEXT: } |
| 116 | + |
| 117 | +// CHECK: sil shared [transparent] @$sSo35static_const_char_with_long_literals4Int8Vvg : $@convention(thin) () -> Int8 { |
| 118 | +// CHECK-NEXT: bb0: |
| 119 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 42 |
| 120 | +// CHECK-NEXT: %1 = struct $Int8 (%0) |
| 121 | +// CHECK-NEXT: return %1 |
| 122 | +// CHECK-NEXT: } |
| 123 | + |
| 124 | +// CHECK: sil shared [transparent] @$sSo39static_const_char_with_overflow_literals4Int8Vvg : $@convention(thin) () -> Int8 { |
| 125 | +// CHECK-NEXT: bb0: |
| 126 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 9 |
| 127 | +// CHECK-NEXT: %1 = struct $Int8 (%0) |
| 128 | +// CHECK-NEXT: return %1 |
| 129 | +// CHECK-NEXT: } |
| 130 | + |
| 131 | +// CHECK: sil shared [transparent] @$sSo17static_const_long{{.*}} : $@convention(thin) () -> {{.*}} { |
| 132 | +// CHECK-NEXT: bb0: |
| 133 | +// CHECK-NEXT: %0 = integer_literal {{.*}}, 42 |
| 134 | +// CHECK-NEXT: %1 = struct {{.*}} (%0) |
| 135 | +// CHECK-NEXT: return %1 |
| 136 | +// CHECK-NEXT: } |
| 137 | + |
| 138 | +// CHECK: sil shared [transparent] @$sSo18static_const_floatSfvg : $@convention(thin) () -> Float { |
| 139 | +// CHECK-NEXT: bb0: |
| 140 | +// CHECK-NEXT: %0 = float_literal $Builtin.FPIEEE32, 0x42280000 // 42 |
| 141 | +// CHECK-NEXT: %1 = struct $Float (%0) |
| 142 | +// CHECK-NEXT: return %1 |
| 143 | +// CHECK-NEXT: } |
| 144 | + |
| 145 | +// CHECK: sil shared [transparent] @$sSo19static_const_doubleSdvg : $@convention(thin) () -> Double { |
| 146 | +// CHECK-NEXT: bb0: |
| 147 | +// CHECK-NEXT: %0 = float_literal $Builtin.FPIEEE64, 0x4045000000000000 // 42 |
| 148 | +// CHECK-NEXT: %1 = struct $Double (%0) |
| 149 | +// CHECK-NEXT: return %1 |
| 150 | +// CHECK-NEXT: } |
| 151 | + |
| 152 | +// CHECK: sil shared [transparent] @$sSo036static_const_char_referencing_other_B0s4Int8Vvg : $@convention(thin) () -> Int8 { |
| 153 | +// CHECK-NEXT: bb0: |
| 154 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 43 |
| 155 | +// CHECK-NEXT: %1 = struct $Int8 (%0) |
| 156 | +// CHECK-NEXT: return %1 |
| 157 | +// CHECK-NEXT: } |
| 158 | + |
| 159 | +// CHECK: sil shared [transparent] @$sSo17static_const_enumSo6MyEnumVvg : $@convention(thin) () -> MyEnum { |
| 160 | +// CHECK-NEXT: bb0: |
| 161 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 1 |
| 162 | +// CHECK-NEXT: %1 = struct $Int8 (%0) |
| 163 | +// CHECK-NEXT: %2 = struct $MyEnum (%1) |
| 164 | +// CHECK-NEXT: return %2 |
| 165 | +// CHECK-NEXT: } |
| 166 | + |
| 167 | +// CHECK: sil shared [transparent] @$sSo8MyStructV28static_const_int_as_a_members5Int32VvgZ : $@convention(method) (@thin MyStruct.Type) -> Int32 { |
| 168 | +// CHECK-NEXT: // %0 "self" |
| 169 | +// CHECK-NEXT: bb0(%0 : $@thin MyStruct.Type): |
| 170 | +// CHECK-NEXT: debug_value %0, let, name "self", argno 1 |
| 171 | +// CHECK-NEXT: %2 = integer_literal $Builtin.Int32, 42 |
| 172 | +// CHECK-NEXT: %3 = struct $Int32 (%2) |
| 173 | +// CHECK-NEXT: return %3 |
| 174 | +// CHECK-NEXT: } |
0 commit comments