Rafael Espindola | ff7cea8 | 2013-09-04 04:12:25 +0000 | [diff] [blame] | 1 | // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s |
Eric Christopher | 37d05cd | 2013-01-16 19:54:35 +0000 | [diff] [blame] | 2 | // PR14471 |
| 3 | |
David Blaikie | 949939c | 2013-08-17 20:01:53 +0000 | [diff] [blame] | 4 | enum X { |
| 5 | Y |
| 6 | }; |
Eric Christopher | 37d05cd | 2013-01-16 19:54:35 +0000 | [diff] [blame] | 7 | class C |
| 8 | { |
| 9 | static int a; |
David Blaikie | d42917f | 2013-01-20 01:19:17 +0000 | [diff] [blame] | 10 | const static bool const_a = true; |
Eric Christopher | 37d05cd | 2013-01-16 19:54:35 +0000 | [diff] [blame] | 11 | protected: |
| 12 | static int b; |
David Blaikie | d42917f | 2013-01-20 01:19:17 +0000 | [diff] [blame] | 13 | const static float const_b = 3.14; |
Eric Christopher | 37d05cd | 2013-01-16 19:54:35 +0000 | [diff] [blame] | 14 | public: |
| 15 | static int c; |
| 16 | const static int const_c = 18; |
| 17 | int d; |
David Blaikie | 949939c | 2013-08-17 20:01:53 +0000 | [diff] [blame] | 18 | static X x_a; |
Eric Christopher | 37d05cd | 2013-01-16 19:54:35 +0000 | [diff] [blame] | 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 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 36 | // CHECK: !MDCompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X") |
| 37 | // CHECK: !MDCompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C") |
| 38 | // |
| 39 | // CHECK: ![[DECL_A:[0-9]+]] = !MDDerivedType(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: !MDDerivedType(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]+]] = !MDDerivedType(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: !MDDerivedType(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]+]] = !MDDerivedType(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: !MDDerivedType(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: !MDDerivedType(tag: DW_TAG_member, name: "x_a" |
| 79 | // CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember) |
David Blaikie | af08085 | 2014-11-21 00:20:58 +0000 | [diff] [blame] | 80 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 81 | // CHECK: !MDCompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>" |
| 82 | // CHECK-NOT: DIFlagFwdDecl |
| 83 | // CHECK-SAME: ){{$}} |
| 84 | // CHECK: !MDDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var" |
David Blaikie | af08085 | 2014-11-21 00:20:58 +0000 | [diff] [blame] | 85 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 86 | // CHECK: [[NS_X:![0-9]+]] = !MDNamespace(name: "x" |
David Blaikie | 423eb5a | 2014-11-19 19:42:40 +0000 | [diff] [blame] | 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 | |
David Blaikie | af08085 | 2014-11-21 00:20:58 +0000 | [diff] [blame] | 96 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 97 | // CHECK: !MDCompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct" |
| 98 | // CHECK: !MDDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var" |
David Blaikie | 423eb5a | 2014-11-19 19:42:40 +0000 | [diff] [blame] | 99 | |
| 100 | int ref() { |
| 101 | return anon_static_decl_struct::anon_static_decl_var; |
| 102 | } |
| 103 | |
David Blaikie | af08085 | 2014-11-21 00:20:58 +0000 | [diff] [blame] | 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 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 116 | // CHECK: !MDGlobalVariable(name: "a", {{.*}}variable: i32* @_ZN1C1aE, declaration: ![[DECL_A]]) |
| 117 | // CHECK: !MDGlobalVariable(name: "b", {{.*}}variable: i32* @_ZN1C1bE, declaration: ![[DECL_B]]) |
| 118 | // CHECK: !MDGlobalVariable(name: "c", {{.*}}variable: i32* @_ZN1C1cE, declaration: ![[DECL_C]]) |
David Blaikie | 8e707bb | 2014-10-14 22:22:17 +0000 | [diff] [blame] | 119 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 120 | // CHECK-NOT: !MDGlobalVariable(name: "anon_static_decl_var" |
David Blaikie | 423eb5a | 2014-11-19 19:42:40 +0000 | [diff] [blame] | 121 | |
David Blaikie | 8e707bb | 2014-10-14 22:22:17 +0000 | [diff] [blame] | 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 |
David Blaikie | d70f3c2 | 2014-10-16 18:38:36 +0000 | [diff] [blame] | 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. |
David Blaikie | 8e707bb | 2014-10-14 22:22:17 +0000 | [diff] [blame] | 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 | }; |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 131 | // CHECK: !MDDerivedType(tag: DW_TAG_member, name: "const_va", |
| 132 | // CHECK-SAME: line: [[@LINE-3]] |
| 133 | // CHECK-SAME: extraData: i32 42 |
David Blaikie | 8e707bb | 2014-10-14 22:22:17 +0000 | [diff] [blame] | 134 | const int V::const_va; |
David Blaikie | 3813b26 | 2014-10-23 16:39:49 +0000 | [diff] [blame] | 135 | |
| 136 | namespace x { |
| 137 | struct y { |
| 138 | static int z; |
| 139 | }; |
| 140 | int y::z; |
| 141 | } |
| 142 | |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame^] | 143 | // CHECK: !MDGlobalVariable(name: "z", |
| 144 | // CHECK-SAME: scope: [[NS_X]] |