blob: c777ccb2aba2987facee49a60ec45a2ccff97825 [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
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +00006// CHECK: @_ZN1C1aE = global i32 4, align 4, !dbg [[A:![0-9]+]]
7// CHECK: @_ZN1C1bE = global i32 2, align 4, !dbg [[B:![0-9]+]]
8// CHECK: @_ZN1C1cE = global i32 1, align 4, !dbg [[C:![0-9]+]]
9
David Blaikie949939c2013-08-17 20:01:53 +000010enum X {
11 Y
12};
Eric Christopher37d05cd2013-01-16 19:54:35 +000013class C
14{
15 static int a;
David Blaikied42917f2013-01-20 01:19:17 +000016 const static bool const_a = true;
Eric Christopher37d05cd2013-01-16 19:54:35 +000017protected:
18 static int b;
Charles Li64a1a812016-04-13 20:00:45 +000019#if __cplusplus >= 201103L
20 constexpr static float const_b = 3.14;
21#else
David Blaikied42917f2013-01-20 01:19:17 +000022 const static float const_b = 3.14;
Charles Li64a1a812016-04-13 20:00:45 +000023#endif
Eric Christopher37d05cd2013-01-16 19:54:35 +000024public:
25 static int c;
26 const static int const_c = 18;
27 int d;
David Blaikie949939c2013-08-17 20:01:53 +000028 static X x_a;
Eric Christopher37d05cd2013-01-16 19:54:35 +000029};
30
Eric Christopher37d05cd2013-01-16 19:54:35 +000031// The definition of C::a drives the emission of class C, which is
32// why the definition of "a" comes before the declarations while
33// "b" and "c" come after.
34
Adrian Prantl5f4740d2016-12-20 02:10:02 +000035// CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]])
36// CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
37// CHECK-SAME: declaration: ![[DECL_A:[0-9]+]])
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +000038//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000039// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000040// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
41// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
42// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>"
43// CHECK-NOT: DIFlagFwdDecl
44// CHECK-SAME: ){{$}}
45// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
46
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000047int C::a = 4;
Adrian Prantl5f4740d2016-12-20 02:10:02 +000048// CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]])
49// CHECK: [[BV]] = distinct !DIGlobalVariable(name: "b",
50// CHECK-SAME: declaration: ![[DECL_B:[0-9]+]])
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +000051// CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
52// CHECK-NOT: size:
53// CHECK-NOT: align:
54// CHECK-NOT: offset:
55// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember)
56//
57// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C")
58//
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000059// CHECK: ![[DECL_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000060// CHECK-NOT: size:
61// CHECK-NOT: align:
62// CHECK-NOT: offset:
63// CHECK-SAME: flags: DIFlagStaticMember)
64//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000065// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
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: DIFlagStaticMember,
70// CHECK-SAME: extraData: i1 true)
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000071
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000072// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000073// CHECK-NOT: size:
74// CHECK-NOT: align:
75// CHECK-NOT: offset:
76// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember,
77// CHECK-SAME: extraData: float 0x{{.*}})
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000078
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000079// CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000080// CHECK-NOT: size:
81// CHECK-NOT: align:
82// CHECK-NOT: offset:
83// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
84//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000085// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000086// CHECK-NOT: size:
87// CHECK-NOT: align:
88// CHECK-NOT: offset:
89// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember,
90// CHECK-SAME: extraData: i32 18)
91//
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000092// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000093// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
David Blaikieaf080852014-11-21 00:20:58 +000094
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000095int C::b = 2;
Adrian Prantl5f4740d2016-12-20 02:10:02 +000096// CHECK: [[C]] = !DIGlobalVariableExpression(var: [[CV:.*]])
97// CHECK: [[CV]] = distinct !DIGlobalVariable(name: "c", {{.*}} declaration: ![[DECL_C]])
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000098int C::c = 1;
David Blaikieaf080852014-11-21 00:20:58 +000099
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000100int main()
101{
102 C instance_C;
103 instance_C.d = 8;
104 return C::c;
105}
106
107// CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var"
David Blaikie423eb5a2014-11-19 19:42:40 +0000108
109// Test this in an anonymous namespace to ensure the type is retained even when
110// it doesn't get automatically retained by the string type reference machinery.
111namespace {
112struct anon_static_decl_struct {
113 static const int anon_static_decl_var = 117;
114};
115}
116
David Blaikieaf080852014-11-21 00:20:58 +0000117
David Blaikie423eb5a2014-11-19 19:42:40 +0000118int ref() {
119 return anon_static_decl_struct::anon_static_decl_var;
120}
121
David Blaikieaf080852014-11-21 00:20:58 +0000122template<typename T>
123struct static_decl_templ {
124 static const int static_decl_templ_var = 7;
125};
126
127template<typename T>
128const int static_decl_templ<T>::static_decl_templ_var;
129
130int static_decl_templ_ref() {
131 return static_decl_templ<int>::static_decl_templ_var;
132}
133
David Blaikie8e707bb2014-10-14 22:22:17 +0000134// Verify that even when a static member declaration is created lazily when
135// creating the definition, the declaration line is that of the canonical
David Blaikied70f3c22014-10-16 18:38:36 +0000136// declaration, not the definition. Also, since we look at the canonical
137// definition, we should also correctly emit the constant value (42) into the
138// debug info.
David Blaikie8e707bb2014-10-14 22:22:17 +0000139struct V {
140 virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization
141 static const int const_va = 42;
142};
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +0000143// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +0000144// CHECK-SAME: line: [[@LINE-3]]
145// CHECK-SAME: extraData: i32 42
David Blaikie8e707bb2014-10-14 22:22:17 +0000146const int V::const_va;
David Blaikie3813b262014-10-23 16:39:49 +0000147
148namespace x {
149struct y {
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000150// CHECK: !DIGlobalVariable(name: "z",
151// CHECK-SAME: scope: [[NS_X:![0-9]+]]
152// CHECK: [[NS_X]] = !DINamespace(name: "x"
David Blaikie3813b262014-10-23 16:39:49 +0000153 static int z;
154};
155int y::z;
156}