|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +// RUN: %target-swiftxx-frontend %t/src/main.swift \ |
| 5 | +// RUN: -import-bridging-header %t/src/test.h \ |
| 6 | +// RUN: -module-name main -I %t -emit-sil | %FileCheck %s |
| 7 | + |
| 8 | +//--- test.h |
| 9 | + |
| 10 | +const int const_int = 42; |
| 11 | +namespace Namespace { |
| 12 | + const int namespaced_const_int = 42; |
| 13 | +} |
| 14 | + |
| 15 | +static inline int foo() { return 42; } |
| 16 | +const int not_really_constant = foo(); |
| 17 | + |
| 18 | +constexpr int constexpr_func() { return 42; } |
| 19 | +constexpr int constexpr_int = constexpr_func(); |
| 20 | +static constexpr int static_constexpr_int = constexpr_func(); |
| 21 | + |
| 22 | +class MyClass { |
| 23 | +public: |
| 24 | + const int class_const_int = 42; // member field, don't expect to import as a global, no CHECKs for this |
| 25 | + static const int class_static_const_int = 42; |
| 26 | +}; |
| 27 | + |
| 28 | +namespace OtherNamespace { |
| 29 | + constexpr int namespaced_constexpr_int = constexpr_func(); |
| 30 | + static constexpr int namespaced_static_constexpr_int = constexpr_func(); |
| 31 | +} |
| 32 | +class OtherClass { |
| 33 | + static constexpr int class_static_constexpr_int = 42; |
| 34 | +}; |
| 35 | + |
| 36 | + |
| 37 | +//--- main.swift |
| 38 | +func foo() { |
| 39 | + print(const_int) |
| 40 | + print(Namespace.namespaced_const_int) |
| 41 | + print(not_really_constant) |
| 42 | + print(constexpr_int) |
| 43 | + print(static_constexpr_int) |
| 44 | + |
| 45 | + // TODO: Non-top-level constexpr variables currently are not imported at all (would be imported as static members) |
| 46 | + //print(OtherNamespace.namespaced_constexpr_int) |
| 47 | + //print(OtherNamespace.namespaced_static_constexpr_int) |
| 48 | + //print(MyClass.class_static_constexpr_int) |
| 49 | + |
| 50 | + print(MyClass().class_const_int) |
| 51 | + print(MyClass.class_static_const_int) |
| 52 | +} |
| 53 | + |
| 54 | +// Only imported as external declarations: |
| 55 | +// CHECK: sil_global public_external [let] @not_really_constant : $Int32 |
| 56 | + |
| 57 | +// CHECK: sil shared [transparent] @$sSo9const_ints5Int32Vvg : $@convention(thin) () -> Int32 { |
| 58 | +// CHECK-NEXT: bb0: |
| 59 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 60 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 61 | +// CHECK-NEXT: return %1 |
| 62 | +// CHECK-NEXT: } |
| 63 | + |
| 64 | +// CHECK: sil shared [transparent] @$sSo9NamespaceO20namespaced_const_ints5Int32VvgZ : $@convention(method) (@thin Namespace.Type) -> Int32 { |
| 65 | +// CHECK-NEXT: // %0 "self" |
| 66 | +// CHECK-NEXT: bb0(%0 : $@thin Namespace.Type): |
| 67 | +// CHECK-NEXT: debug_value %0, let, name "self", argno 1 |
| 68 | +// CHECK-NEXT: %2 = integer_literal $Builtin.Int32, 42 |
| 69 | +// CHECK-NEXT: %3 = struct $Int32 (%2) |
| 70 | +// CHECK-NEXT: return %3 |
| 71 | +// CHECK-NEXT: } |
| 72 | + |
| 73 | +// CHECK: sil shared [transparent] @$sSo13constexpr_ints5Int32Vvg : $@convention(thin) () -> Int32 { |
| 74 | +// CHECK-NEXT: bb0: |
| 75 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 76 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 77 | +// CHECK-NEXT: return %1 |
| 78 | +// CHECK-NEXT: } |
| 79 | + |
| 80 | +// CHECK: sil shared [transparent] @$sSo20static_constexpr_ints5Int32Vvg : $@convention(thin) () -> Int32 { |
| 81 | +// CHECK-NEXT: bb0: |
| 82 | +// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 42 |
| 83 | +// CHECK-NEXT: %1 = struct $Int32 (%0) |
| 84 | +// CHECK-NEXT: return %1 |
| 85 | +// CHECK-NEXT: } |
| 86 | + |
| 87 | +// CHECK: sil shared [transparent] @$sSo7MyClassV22class_static_const_ints5Int32VvgZ : $@convention(method) (@thin MyClass.Type) -> Int32 { |
| 88 | +// CHECK-NEXT: // %0 "self" |
| 89 | +// CHECK-NEXT: bb0(%0 : $@thin MyClass.Type): |
| 90 | +// CHECK-NEXT: debug_value %0, let, name "self", argno 1 |
| 91 | +// CHECK-NEXT: %2 = integer_literal $Builtin.Int32, 42 |
| 92 | +// CHECK-NEXT: %3 = struct $Int32 (%2) |
| 93 | +// CHECK-NEXT: return %3 |
| 94 | +// CHECK-NEXT: } |
0 commit comments