11// RUN: %empty-directory(%t/src)
22// RUN: split-file %s %t/src
33
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 \
55// 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
79
810//--- test.h
911#include < stdbool. h>
@@ -16,18 +18,28 @@ static const int static_const_int = 42;
1618
1719static const bool static _const_bool = true ;
1820static 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
1923static const long static _const_long = 42 ;
2024static const float static _const_float = 42.0 ;
2125static const do uble static _const_double = 42.0 ;
2226
2327static const char static _const_char_array [ 4 ] = { 1 , 2 , 3 , 4 } ;
2428static const char * static _const_pointer = 0 ;
2529
30+ static const char static _const_char_referencing_other_const = 1 + static_const_char;
31+
2632typedef enum MyEnum : char {
2733 MyEnumCase0 = 0 , MyEnumCase1 , MyEnumCase2
2834} MyEnum;
2935static const MyEnum static _const_enum = MyEnumCase1;
3036
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+
3143//--- main.swift
3244func foo( ) {
3345 print ( MACRO_INT)
@@ -38,14 +50,20 @@ func foo() {
3850
3951 print ( static_const_bool)
4052 print ( static_const_char)
53+ print ( static_const_char_with_long_literal)
54+ print ( static_const_char_with_overflow_literal)
4155 print ( static_const_long)
4256 print ( static_const_float)
4357 print ( static_const_double)
4458
4559 print ( static_const_char_array)
4660 print ( static_const_pointer)
4761
62+ print ( static_const_char_referencing_other_const)
63+
4864 print ( static_const_enum)
65+
66+ print ( MyStruct . static_const_int_as_a_member)
4967}
5068
5169// Globals that don't get their value imported stay as public_external:
@@ -88,6 +106,20 @@ func foo() {
88106// CHECK-NEXT: return %1
89107// CHECK-NEXT: }
90108
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+
91123// CHECK: sil shared [transparent] @$sSo17static_const_longSivg : $@convention(thin) () -> Int {
92124// CHECK-NEXT: bb0:
93125// CHECK-NEXT: %0 = integer_literal $Builtin.Int64, 42
@@ -109,10 +141,26 @@ func foo() {
109141// CHECK-NEXT: return %1
110142// CHECK-NEXT: }
111143
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+
112151// CHECK: sil shared [transparent] @$sSo17static_const_enumSo6MyEnumVvg : $@convention(thin) () -> MyEnum {
113152// CHECK-NEXT: bb0:
114153// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 1
115154// CHECK-NEXT: %1 = struct $Int8 (%0)
116155// CHECK-NEXT: %2 = struct $MyEnum (%1)
117156// CHECK-NEXT: return %2
118157// 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