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: metadata !"_ZTS1X"} ; [ DW_TAG_enumeration_type ] [X]
37 // CHECK: metadata !"_ZTS1C"} ; [ DW_TAG_class_type ] [C]
38 // CHECK: ![[DECL_A:[0-9]+]] = metadata {{.*}} [ DW_TAG_member ] [a] [line {{.*}}, size 0, align 0, offset 0] [static]
39 // CHECK: metadata !"0xd\00const_a\00{{.*}}", {{.*}}, i1 true} ; [ DW_TAG_member ] [const_a] [line {{.*}}, size 0, align 0, offset 0] [static]
40 // CHECK: ![[DECL_B:[0-9]+]] = metadata !{metadata !"0xd\00b\00{{.*}}", {{.*}} [ DW_TAG_member ] [b] [line {{.*}}, size 0, align 0, offset 0] [protected] [static]
41 // CHECK: metadata !"0xd\00const_b\00{{.*}}", {{.*}}, float 0x{{.*}}} ; [ DW_TAG_member ] [const_b] [line {{.*}}, size 0, align 0, offset 0] [protected] [static]
42 // CHECK: ![[DECL_C:[0-9]+]] = metadata !{metadata !"0xd\00c\00{{.*}}", {{.*}} [ DW_TAG_member ] [c] [line {{.*}}, size 0, align 0, offset 0] [public] [static]
43 // CHECK: metadata !"0xd\00const_c\00{{.*}}", {{.*}} [ DW_TAG_member ] [const_c] [line {{.*}}, size 0, align 0, offset 0] [public] [static]
44 // CHECK: metadata !"0xd\00x_a\00{{.*}}", {{.*}} [ DW_TAG_member ] [x_a] {{.*}} [public] [static]
45 // CHECK: metadata !{metadata !"0x34\00a\00{{.*}}", {{.*}} @_ZN1C1aE, metadata ![[DECL_A]]} ; [ DW_TAG_variable ] [a] {{.*}} [def]
46 // CHECK: metadata !{metadata !"0x34\00b\00{{.*}}", {{.*}} @_ZN1C1bE, metadata ![[DECL_B]]} ; [ DW_TAG_variable ] [b] {{.*}} [def]
47 // CHECK: metadata !{metadata !"0x34\00c\00{{.*}}", {{.*}} @_ZN1C1cE, metadata ![[DECL_C]]} ; [ DW_TAG_variable ] [c] {{.*}} [def]
48 
49 // Verify that even when a static member declaration is created lazily when
50 // creating the definition, the declaration line is that of the canonical
51 // declaration, not the definition. Also, since we look at the canonical
52 // definition, we should also correctly emit the constant value (42) into the
53 // debug info.
54 struct V {
55   virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization
56   static const int const_va = 42;
57 };
58 // CHECK: i32 42} ; [ DW_TAG_member ] [const_va] [line [[@LINE-2]],
59 const int V::const_va;
60