1
1
// RUN: %empty-directory(%t/src)
2
2
// RUN: split-file %s %t/src
3
3
4
- // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %t/src/main.swift \
4
+ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %t/src/main.swift \
5
5
// RUN: -import-bridging-header %t/src/test.h \
6
- // RUN: -module-name main -I %t -emit-sil | %FileCheck %s
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
7
9
8
10
//--- test.h
9
11
#include < stdbool. h>
@@ -16,18 +18,28 @@ static const int static_const_int = 42;
16
18
17
19
static const bool static _const_bool = true ;
18
20
static const char static _const_char = 42 ;
21
+ static const char static _const_char_with_long_literal = 42 ull;
22
+ static const char static _const_char_with_overflow_literal = 777 ull; // CHECK-DIAG: [[@LINE]]:{{.*}}: warning: implicit conversion from 'unsigned long long' to 'char' changes value from 777 to 9
19
23
static const long static _const_long = 42 ;
20
24
static const float static _const_float = 42.0 ;
21
25
static const do uble static _const_double = 42.0 ;
22
26
23
27
static const char static _const_char_array [ 4 ] = { 1 , 2 , 3 , 4 } ;
24
28
static const char * static _const_pointer = 0 ;
25
29
30
+ static const char static _const_char_referencing_other_const = 1 + static_const_char;
31
+
26
32
typedef enum MyEnum : char {
27
33
MyEnumCase0 = 0 , MyEnumCase1 , MyEnumCase2
28
34
} MyEnum;
29
35
static const MyEnum static _const_enum = MyEnumCase1;
30
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
+
31
43
//--- main.swift
32
44
func foo( ) {
33
45
print ( MACRO_INT)
@@ -38,14 +50,20 @@ func foo() {
38
50
39
51
print ( static_const_bool)
40
52
print ( static_const_char)
53
+ print ( static_const_char_with_long_literal)
54
+ print ( static_const_char_with_overflow_literal)
41
55
print ( static_const_long)
42
56
print ( static_const_float)
43
57
print ( static_const_double)
44
58
45
59
print ( static_const_char_array)
46
60
print ( static_const_pointer)
47
61
62
+ print ( static_const_char_referencing_other_const)
63
+
48
64
print ( static_const_enum)
65
+
66
+ print ( MyStruct . static_const_int_as_a_member)
49
67
}
50
68
51
69
// Globals that don't get their value imported stay as public_external:
@@ -88,6 +106,20 @@ func foo() {
88
106
// CHECK-NEXT: return %1
89
107
// CHECK-NEXT: }
90
108
109
+ // CHECK: sil shared [transparent] @$sSo35static_const_char_with_long_literals4Int8Vvg : $@convention(thin) () -> Int8 {
110
+ // CHECK-NEXT: bb0:
111
+ // CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 42
112
+ // CHECK-NEXT: %1 = struct $Int8 (%0)
113
+ // CHECK-NEXT: return %1
114
+ // CHECK-NEXT: }
115
+
116
+ // CHECK: sil shared [transparent] @$sSo39static_const_char_with_overflow_literals4Int8Vvg : $@convention(thin) () -> Int8 {
117
+ // CHECK-NEXT: bb0:
118
+ // CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 9
119
+ // CHECK-NEXT: %1 = struct $Int8 (%0)
120
+ // CHECK-NEXT: return %1
121
+ // CHECK-NEXT: }
122
+
91
123
// CHECK: sil shared [transparent] @$sSo17static_const_longSivg : $@convention(thin) () -> Int {
92
124
// CHECK-NEXT: bb0:
93
125
// CHECK-NEXT: %0 = integer_literal $Builtin.Int64, 42
@@ -109,10 +141,26 @@ func foo() {
109
141
// CHECK-NEXT: return %1
110
142
// CHECK-NEXT: }
111
143
144
+ // CHECK: sil shared [transparent] @$sSo036static_const_char_referencing_other_B0s4Int8Vvg : $@convention(thin) () -> Int8 {
145
+ // CHECK-NEXT: bb0:
146
+ // CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 43
147
+ // CHECK-NEXT: %1 = struct $Int8 (%0)
148
+ // CHECK-NEXT: return %1
149
+ // CHECK-NEXT: }
150
+
112
151
// CHECK: sil shared [transparent] @$sSo17static_const_enumSo6MyEnumVvg : $@convention(thin) () -> MyEnum {
113
152
// CHECK-NEXT: bb0:
114
153
// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 1
115
154
// CHECK-NEXT: %1 = struct $Int8 (%0)
116
155
// CHECK-NEXT: %2 = struct $MyEnum (%1)
117
156
// CHECK-NEXT: return %2
118
157
// CHECK-NEXT: }
158
+
159
+ // CHECK: sil shared [transparent] @$sSo8MyStructV28static_const_int_as_a_members5Int32VvgZ : $@convention(method) (@thin MyStruct.Type) -> Int32 {
160
+ // CHECK-NEXT: // %0 "self"
161
+ // CHECK-NEXT: bb0(%0 : $@thin MyStruct.Type):
162
+ // CHECK-NEXT: debug_value %0, let, name "self", argno 1
163
+ // CHECK-NEXT: %2 = integer_literal $Builtin.Int32, 42
164
+ // CHECK-NEXT: %3 = struct $Int32 (%2)
165
+ // CHECK-NEXT: return %3
166
+ // CHECK-NEXT: }
0 commit comments