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: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X") 37 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C") 38 // 39 // CHECK: ![[DECL_A:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "a" 40 // CHECK-NOT: size: 41 // CHECK-NOT: align: 42 // CHECK-NOT: offset: 43 // CHECK-SAME: flags: DIFlagStaticMember) 44 // 45 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a" 46 // CHECK-NOT: size: 47 // CHECK-NOT: align: 48 // CHECK-NOT: offset: 49 // CHECK-SAME: flags: DIFlagStaticMember, 50 // CHECK-SAME: extraData: i1 true) 51 // 52 // CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "b" 53 // CHECK-NOT: size: 54 // CHECK-NOT: align: 55 // CHECK-NOT: offset: 56 // CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember) 57 // 58 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b" 59 // CHECK-NOT: size: 60 // CHECK-NOT: align: 61 // CHECK-NOT: offset: 62 // CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember, 63 // CHECK-SAME: extraData: float 0x{{.*}}) 64 // 65 // CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c" 66 // CHECK-NOT: size: 67 // CHECK-NOT: align: 68 // CHECK-NOT: offset: 69 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember) 70 // 71 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c" 72 // CHECK-NOT: size: 73 // CHECK-NOT: align: 74 // CHECK-NOT: offset: 75 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember, 76 // CHECK-SAME: extraData: i32 18) 77 // 78 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a" 79 // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember) 80 81 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>" 82 // CHECK-NOT: DIFlagFwdDecl 83 // CHECK-SAME: ){{$}} 84 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var" 85 86 // CHECK: [[NS_X:![0-9]+]] = !DINamespace(name: "x" 87 88 // Test this in an anonymous namespace to ensure the type is retained even when 89 // it doesn't get automatically retained by the string type reference machinery. 90 namespace { 91 struct anon_static_decl_struct { 92 static const int anon_static_decl_var = 117; 93 }; 94 } 95 96 97 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct" 98 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var" 99 100 int ref() { 101 return anon_static_decl_struct::anon_static_decl_var; 102 } 103 104 template<typename T> 105 struct static_decl_templ { 106 static const int static_decl_templ_var = 7; 107 }; 108 109 template<typename T> 110 const int static_decl_templ<T>::static_decl_templ_var; 111 112 int static_decl_templ_ref() { 113 return static_decl_templ<int>::static_decl_templ_var; 114 } 115 116 // CHECK: !DIGlobalVariable(name: "a", {{.*}}variable: i32* @_ZN1C1aE, declaration: ![[DECL_A]]) 117 // CHECK: !DIGlobalVariable(name: "b", {{.*}}variable: i32* @_ZN1C1bE, declaration: ![[DECL_B]]) 118 // CHECK: !DIGlobalVariable(name: "c", {{.*}}variable: i32* @_ZN1C1cE, declaration: ![[DECL_C]]) 119 120 // CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var" 121 122 // Verify that even when a static member declaration is created lazily when 123 // creating the definition, the declaration line is that of the canonical 124 // declaration, not the definition. Also, since we look at the canonical 125 // definition, we should also correctly emit the constant value (42) into the 126 // debug info. 127 struct V { 128 virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization 129 static const int const_va = 42; 130 }; 131 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va", 132 // CHECK-SAME: line: [[@LINE-3]] 133 // CHECK-SAME: extraData: i32 42 134 const int V::const_va; 135 136 namespace x { 137 struct y { 138 static int z; 139 }; 140 int y::z; 141 } 142 143 // CHECK: !DIGlobalVariable(name: "z", 144 // CHECK-SAME: scope: [[NS_X]] 145