1 // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s 2 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s 3 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s 4 // PR14471 5 6 enum X { 7 Y 8 }; 9 class C 10 { 11 static int a; 12 const static bool const_a = true; 13 protected: 14 static int b; 15 #if __cplusplus >= 201103L 16 constexpr static float const_b = 3.14; 17 #else 18 const static float const_b = 3.14; 19 #endif 20 public: 21 static int c; 22 const static int const_c = 18; 23 int d; 24 static X x_a; 25 }; 26 27 int C::a = 4; 28 int C::b = 2; 29 int C::c = 1; 30 31 int main() 32 { 33 C instance_C; 34 instance_C.d = 8; 35 return C::c; 36 } 37 38 // The definition of C::a drives the emission of class C, which is 39 // why the definition of "a" comes before the declarations while 40 // "b" and "c" come after. 41 42 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X") 43 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C") 44 // 45 // CHECK: ![[DECL_A:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "a" 46 // CHECK-NOT: size: 47 // CHECK-NOT: align: 48 // CHECK-NOT: offset: 49 // CHECK-SAME: flags: DIFlagStaticMember) 50 // 51 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a" 52 // CHECK-NOT: size: 53 // CHECK-NOT: align: 54 // CHECK-NOT: offset: 55 // CHECK-SAME: flags: DIFlagStaticMember, 56 // CHECK-SAME: extraData: i1 true) 57 // 58 // CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "b" 59 // CHECK-NOT: size: 60 // CHECK-NOT: align: 61 // CHECK-NOT: offset: 62 // CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember) 63 // 64 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b" 65 // CHECK-NOT: size: 66 // CHECK-NOT: align: 67 // CHECK-NOT: offset: 68 // CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember, 69 // CHECK-SAME: extraData: float 0x{{.*}}) 70 // 71 // CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c" 72 // CHECK-NOT: size: 73 // CHECK-NOT: align: 74 // CHECK-NOT: offset: 75 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember) 76 // 77 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c" 78 // CHECK-NOT: size: 79 // CHECK-NOT: align: 80 // CHECK-NOT: offset: 81 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember, 82 // CHECK-SAME: extraData: i32 18) 83 // 84 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a" 85 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember) 86 87 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>" 88 // CHECK-NOT: DIFlagFwdDecl 89 // CHECK-SAME: ){{$}} 90 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var" 91 92 // CHECK: [[NS_X:![0-9]+]] = !DINamespace(name: "x" 93 94 // Test this in an anonymous namespace to ensure the type is retained even when 95 // it doesn't get automatically retained by the string type reference machinery. 96 namespace { 97 struct anon_static_decl_struct { 98 static const int anon_static_decl_var = 117; 99 }; 100 } 101 102 103 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct" 104 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var" 105 106 int ref() { 107 return anon_static_decl_struct::anon_static_decl_var; 108 } 109 110 template<typename T> 111 struct static_decl_templ { 112 static const int static_decl_templ_var = 7; 113 }; 114 115 template<typename T> 116 const int static_decl_templ<T>::static_decl_templ_var; 117 118 int static_decl_templ_ref() { 119 return static_decl_templ<int>::static_decl_templ_var; 120 } 121 122 // CHECK: !DIGlobalVariable(name: "a", {{.*}}variable: i32* @_ZN1C1aE, declaration: ![[DECL_A]]) 123 // CHECK: !DIGlobalVariable(name: "b", {{.*}}variable: i32* @_ZN1C1bE, declaration: ![[DECL_B]]) 124 // CHECK: !DIGlobalVariable(name: "c", {{.*}}variable: i32* @_ZN1C1cE, declaration: ![[DECL_C]]) 125 126 // CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var" 127 128 // Verify that even when a static member declaration is created lazily when 129 // creating the definition, the declaration line is that of the canonical 130 // declaration, not the definition. Also, since we look at the canonical 131 // definition, we should also correctly emit the constant value (42) into the 132 // debug info. 133 struct V { 134 virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization 135 static const int const_va = 42; 136 }; 137 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va", 138 // CHECK-SAME: line: [[@LINE-3]] 139 // CHECK-SAME: extraData: i32 42 140 const int V::const_va; 141 142 namespace x { 143 struct y { 144 static int z; 145 }; 146 int y::z; 147 } 148 149 // CHECK: !DIGlobalVariable(name: "z", 150 // CHECK-SAME: scope: [[NS_X]] 151