1 // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s 2 // PR14471 3 4 enum X { 5 Y 6 }; 7 class C 8 { 9 static int a; 10 const static bool const_a = true; 11 protected: 12 static int b; 13 const static float const_b = 3.14; 14 public: 15 static int c; 16 const static int const_c = 18; 17 int d; 18 static X x_a; 19 }; 20 21 int C::a = 4; 22 int C::b = 2; 23 int C::c = 1; 24 25 int main() 26 { 27 C instance_C; 28 instance_C.d = 8; 29 return C::c; 30 } 31 32 // The definition of C::a drives the emission of class C, which is 33 // why the definition of "a" comes before the declarations while 34 // "b" and "c" come after. 35 36 // CHECK: !"_ZTS1X"} ; [ DW_TAG_enumeration_type ] [X] 37 // CHECK: !"_ZTS1C"} ; [ DW_TAG_class_type ] [C] 38 // CHECK: ![[DECL_A:[0-9]+]] = {{.*}} [ DW_TAG_member ] [a] [line {{.*}}, size 0, align 0, offset 0] [static] 39 // CHECK: !"0xd\00const_a\00{{.*}}", {{.*}}, i1 true} ; [ DW_TAG_member ] [const_a] [line {{.*}}, size 0, align 0, offset 0] [static] 40 // CHECK: ![[DECL_B:[0-9]+]] = !{!"0xd\00b\00{{.*}}", {{.*}} [ DW_TAG_member ] [b] [line {{.*}}, size 0, align 0, offset 0] [protected] [static] 41 // CHECK: !"0xd\00const_b\00{{.*}}", {{.*}}, float 0x{{.*}}} ; [ DW_TAG_member ] [const_b] [line {{.*}}, size 0, align 0, offset 0] [protected] [static] 42 // CHECK: ![[DECL_C:[0-9]+]] = !{!"0xd\00c\00{{.*}}", {{.*}} [ DW_TAG_member ] [c] [line {{.*}}, size 0, align 0, offset 0] [public] [static] 43 // CHECK: !"0xd\00const_c\00{{.*}}", {{.*}} [ DW_TAG_member ] [const_c] [line {{.*}}, size 0, align 0, offset 0] [public] [static] 44 // CHECK: !"0xd\00x_a\00{{.*}}", {{.*}} [ DW_TAG_member ] [x_a] {{.*}} [public] [static] 45 46 // CHECK: ; [ DW_TAG_structure_type ] [static_decl_templ<int>] {{.*}} [def] 47 // CHECK: ; [ DW_TAG_member ] [static_decl_templ_var] 48 49 // CHECK: [[NS_X:![0-9]+]] = {{.*}} ; [ DW_TAG_namespace ] [x] 50 51 // Test this in an anonymous namespace to ensure the type is retained even when 52 // it doesn't get automatically retained by the string type reference machinery. 53 namespace { 54 struct anon_static_decl_struct { 55 static const int anon_static_decl_var = 117; 56 }; 57 } 58 59 60 // CHECK: ; [ DW_TAG_structure_type ] [anon_static_decl_struct] {{.*}} [def] 61 // CHECK: ; [ DW_TAG_member ] [anon_static_decl_var] 62 63 int ref() { 64 return anon_static_decl_struct::anon_static_decl_var; 65 } 66 67 template<typename T> 68 struct static_decl_templ { 69 static const int static_decl_templ_var = 7; 70 }; 71 72 template<typename T> 73 const int static_decl_templ<T>::static_decl_templ_var; 74 75 int static_decl_templ_ref() { 76 return static_decl_templ<int>::static_decl_templ_var; 77 } 78 79 // CHECK: !"0x34\00a\00{{.*}}", null, {{.*}} @_ZN1C1aE, ![[DECL_A]]} ; [ DW_TAG_variable ] [a] {{.*}} [def] 80 // CHECK: !"0x34\00b\00{{.*}}", null, {{.*}} @_ZN1C1bE, ![[DECL_B]]} ; [ DW_TAG_variable ] [b] {{.*}} [def] 81 // CHECK: !"0x34\00c\00{{.*}}", null, {{.*}} @_ZN1C1cE, ![[DECL_C]]} ; [ DW_TAG_variable ] [c] {{.*}} [def] 82 83 // CHECK-NOT: ; [ DW_TAG_variable ] [anon_static_decl_var] 84 85 // Verify that even when a static member declaration is created lazily when 86 // creating the definition, the declaration line is that of the canonical 87 // declaration, not the definition. Also, since we look at the canonical 88 // definition, we should also correctly emit the constant value (42) into the 89 // debug info. 90 struct V { 91 virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization 92 static const int const_va = 42; 93 }; 94 // CHECK: i32 42} ; [ DW_TAG_member ] [const_va] [line [[@LINE-2]], 95 const int V::const_va; 96 97 namespace x { 98 struct y { 99 static int z; 100 }; 101 int y::z; 102 } 103 104 // CHECK: !"0x34\00z\00{{.*}}", [[NS_X]], {{.*}} ; [ DW_TAG_variable ] [z] {{.*}} [def] 105