blob: 8e5207d5c30b6d1a7050f276ae41ecd83c67e174 [file] [log] [blame]
Rafael Espindolaff7cea82013-09-04 04:12:25 +00001// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
Eric Christopher37d05cd2013-01-16 19:54:35 +00002// PR14471
3
David Blaikie949939c2013-08-17 20:01:53 +00004enum X {
5 Y
6};
Eric Christopher37d05cd2013-01-16 19:54:35 +00007class C
8{
9 static int a;
David Blaikied42917f2013-01-20 01:19:17 +000010 const static bool const_a = true;
Eric Christopher37d05cd2013-01-16 19:54:35 +000011protected:
12 static int b;
David Blaikied42917f2013-01-20 01:19:17 +000013 const static float const_b = 3.14;
Eric Christopher37d05cd2013-01-16 19:54:35 +000014public:
15 static int c;
16 const static int const_c = 18;
17 int d;
David Blaikie949939c2013-08-17 20:01:53 +000018 static X x_a;
Eric Christopher37d05cd2013-01-16 19:54:35 +000019};
20
21int C::a = 4;
22int C::b = 2;
23int C::c = 1;
24
25int 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 Smith9dd4e4e2015-04-29 16:40:08 +000036// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
37// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C")
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000038//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000039// CHECK: ![[DECL_A:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000040// CHECK-NOT: size:
41// CHECK-NOT: align:
42// CHECK-NOT: offset:
43// CHECK-SAME: flags: DIFlagStaticMember)
44//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000045// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000046// CHECK-NOT: size:
47// CHECK-NOT: align:
48// CHECK-NOT: offset:
49// CHECK-SAME: flags: DIFlagStaticMember,
50// CHECK-SAME: extraData: i1 true)
51//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000052// CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000053// CHECK-NOT: size:
54// CHECK-NOT: align:
55// CHECK-NOT: offset:
56// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember)
57//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000058// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000059// CHECK-NOT: size:
60// CHECK-NOT: align:
61// CHECK-NOT: offset:
62// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember,
63// CHECK-SAME: extraData: float 0x{{.*}})
64//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000065// CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000066// CHECK-NOT: size:
67// CHECK-NOT: align:
68// CHECK-NOT: offset:
69// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
70//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000071// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000072// CHECK-NOT: size:
73// CHECK-NOT: align:
74// CHECK-NOT: offset:
75// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember,
76// CHECK-SAME: extraData: i32 18)
77//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000078// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000079// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
David Blaikieaf080852014-11-21 00:20:58 +000080
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000081// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000082// CHECK-NOT: DIFlagFwdDecl
83// CHECK-SAME: ){{$}}
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000084// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
David Blaikieaf080852014-11-21 00:20:58 +000085
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000086// CHECK: [[NS_X:![0-9]+]] = !DINamespace(name: "x"
David Blaikie423eb5a2014-11-19 19:42:40 +000087
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.
90namespace {
91struct anon_static_decl_struct {
92 static const int anon_static_decl_var = 117;
93};
94}
95
David Blaikieaf080852014-11-21 00:20:58 +000096
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000097// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
98// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
David Blaikie423eb5a2014-11-19 19:42:40 +000099
100int ref() {
101 return anon_static_decl_struct::anon_static_decl_var;
102}
103
David Blaikieaf080852014-11-21 00:20:58 +0000104template<typename T>
105struct static_decl_templ {
106 static const int static_decl_templ_var = 7;
107};
108
109template<typename T>
110const int static_decl_templ<T>::static_decl_templ_var;
111
112int static_decl_templ_ref() {
113 return static_decl_templ<int>::static_decl_templ_var;
114}
115
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000116// 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]])
David Blaikie8e707bb2014-10-14 22:22:17 +0000119
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000120// CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var"
David Blaikie423eb5a2014-11-19 19:42:40 +0000121
David Blaikie8e707bb2014-10-14 22:22:17 +0000122// 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 Blaikied70f3c22014-10-16 18:38:36 +0000124// 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 Blaikie8e707bb2014-10-14 22:22:17 +0000127struct 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 Smith9dd4e4e2015-04-29 16:40:08 +0000131// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +0000132// CHECK-SAME: line: [[@LINE-3]]
133// CHECK-SAME: extraData: i32 42
David Blaikie8e707bb2014-10-14 22:22:17 +0000134const int V::const_va;
David Blaikie3813b262014-10-23 16:39:49 +0000135
136namespace x {
137struct y {
138 static int z;
139};
140int y::z;
141}
142
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000143// CHECK: !DIGlobalVariable(name: "z",
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +0000144// CHECK-SAME: scope: [[NS_X]]