blob: 81ab203418b311a04dc72ec860f1c8f1a57661ce [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
Charles Li64a1a812016-04-13 20:00:45 +00002// 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
Eric Christopher37d05cd2013-01-16 19:54:35 +00004// PR14471
5
David Blaikie949939c2013-08-17 20:01:53 +00006enum X {
7 Y
8};
Eric Christopher37d05cd2013-01-16 19:54:35 +00009class C
10{
11 static int a;
David Blaikied42917f2013-01-20 01:19:17 +000012 const static bool const_a = true;
Eric Christopher37d05cd2013-01-16 19:54:35 +000013protected:
14 static int b;
Charles Li64a1a812016-04-13 20:00:45 +000015#if __cplusplus >= 201103L
16 constexpr static float const_b = 3.14;
17#else
David Blaikied42917f2013-01-20 01:19:17 +000018 const static float const_b = 3.14;
Charles Li64a1a812016-04-13 20:00:45 +000019#endif
Eric Christopher37d05cd2013-01-16 19:54:35 +000020public:
21 static int c;
22 const static int const_c = 18;
23 int d;
David Blaikie949939c2013-08-17 20:01:53 +000024 static X x_a;
Eric Christopher37d05cd2013-01-16 19:54:35 +000025};
26
27int C::a = 4;
28int C::b = 2;
29int C::c = 1;
30
31int 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
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000042// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
43// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C")
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000044//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000045// CHECK: ![[DECL_A:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "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//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000051// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000052// CHECK-NOT: size:
53// CHECK-NOT: align:
54// CHECK-NOT: offset:
55// CHECK-SAME: flags: DIFlagStaticMember,
56// CHECK-SAME: extraData: i1 true)
57//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000058// CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "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//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000064// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000065// CHECK-NOT: size:
66// CHECK-NOT: align:
67// CHECK-NOT: offset:
68// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember,
69// CHECK-SAME: extraData: float 0x{{.*}})
70//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000071// CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "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//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000077// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000078// CHECK-NOT: size:
79// CHECK-NOT: align:
80// CHECK-NOT: offset:
81// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember,
82// CHECK-SAME: extraData: i32 18)
83//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000084// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000085// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
David Blaikieaf080852014-11-21 00:20:58 +000086
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000087// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000088// CHECK-NOT: DIFlagFwdDecl
89// CHECK-SAME: ){{$}}
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000090// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
David Blaikieaf080852014-11-21 00:20:58 +000091
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000092// CHECK: [[NS_X:![0-9]+]] = !DINamespace(name: "x"
David Blaikie423eb5a2014-11-19 19:42:40 +000093
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.
96namespace {
97struct anon_static_decl_struct {
98 static const int anon_static_decl_var = 117;
99};
100}
101
David Blaikieaf080852014-11-21 00:20:58 +0000102
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000103// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
104// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
David Blaikie423eb5a2014-11-19 19:42:40 +0000105
106int ref() {
107 return anon_static_decl_struct::anon_static_decl_var;
108}
109
David Blaikieaf080852014-11-21 00:20:58 +0000110template<typename T>
111struct static_decl_templ {
112 static const int static_decl_templ_var = 7;
113};
114
115template<typename T>
116const int static_decl_templ<T>::static_decl_templ_var;
117
118int static_decl_templ_ref() {
119 return static_decl_templ<int>::static_decl_templ_var;
120}
121
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000122// 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]])
David Blaikie8e707bb2014-10-14 22:22:17 +0000125
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000126// CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var"
David Blaikie423eb5a2014-11-19 19:42:40 +0000127
David Blaikie8e707bb2014-10-14 22:22:17 +0000128// Verify that even when a static member declaration is created lazily when
129// creating the definition, the declaration line is that of the canonical
David Blaikied70f3c22014-10-16 18:38:36 +0000130// 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.
David Blaikie8e707bb2014-10-14 22:22:17 +0000133struct 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};
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000137// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +0000138// CHECK-SAME: line: [[@LINE-3]]
139// CHECK-SAME: extraData: i32 42
David Blaikie8e707bb2014-10-14 22:22:17 +0000140const int V::const_va;
David Blaikie3813b262014-10-23 16:39:49 +0000141
142namespace x {
143struct y {
144 static int z;
145};
146int y::z;
147}
148
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000149// CHECK: !DIGlobalVariable(name: "z",
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +0000150// CHECK-SAME: scope: [[NS_X]]