Clang Project

clang_source_code/test/CodeGenCXX/debug-info.cpp
1// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=BOTH
2// RUN: %clang_cc1 -triple i686-pc-windows-msvc -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=MSVC --check-prefix=BOTH
3
4// CHECK: @_ZN6pr96081xE = global [3 x i8]* null, align 8, !dbg [[X:![0-9]+]]
5
6// CHECK: define void @_ZN7pr147634funcENS_3fooE
7// CHECK: call void @llvm.dbg.declare({{.*}}, metadata ![[F:[0-9]+]], metadata !DIExpression())
8
9// !llvm.dbg.cu pulls in globals and their types first.
10// CHECK-NOT: !DIGlobalVariable(name: "c"
11// CHECK: [[X]] = !DIGlobalVariableExpression(var: [[XV:!.*]], expr: !DIExpression())
12// CHECK: [[XV]] = distinct !DIGlobalVariable(name: "x", linkageName: "_ZN6pr96081xE"
13// CHECK-SAME:                                type: [[INCARRAYPTR:![0-9]*]]
14// CHECK: [[INCARRAYPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[INCARRAY:![0-9]+]]
15// CHECK: [[INCARRAY]] = !DICompositeType(tag: DW_TAG_array_type
16// CHECK-NOT:                             line:
17// CHECK-NOT:                             size:
18// CHECK-NOT:                             align:
19// CHECK-NOT:                             offset:
20// CHECK-SAME:                            baseType: ![[INCTYPE:[0-9]+]]
21
22// CHECK: ![[INCTYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete"
23// CHECK-SAME:                                   DIFlagFwdDecl
24
25template<typename T> struct Identity {
26  typedef T Type;
27};
28
29void f(Identity<int>::Type a) {}
30void f(Identity<int> a) {}
31void f(int& a) { }
32
33template<typename T> struct A {
34  A<T> *next;
35};
36void f(A<int>) { }
37
38struct B { };
39
40void f() {
41  int B::*a = 0;
42  void (B::*b)() = 0;
43}
44
45namespace EmptyNameCrash {
46  struct A { A(); };
47  typedef struct { A x; } B;
48  B x;
49}
50
51// PR4890
52namespace PR4890 {
53  struct X {
54    ~X();
55  };
56
57  X::~X() { }
58}
59
60namespace VirtualDtor {
61  struct Y {
62    virtual ~Y();
63  };
64  
65  Y::~Y() { }
66}
67
68namespace VirtualBase {
69  struct A { int a; };
70  struct B : virtual A { int b; };
71// BOTH: ![[VBASE_B:[0-9]+]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "B",{{.*}} line: [[@LINE-1]],
72// MSVC-SAME:                                        size: 96
73// CHECK-SAME:                                       size: 128,
74// BOTH-NOT:                                         offset:
75// BOTH-NOT:                                         DIFlagFwdDecl
76// BOTH-SAME:                                        elements: [[VBASE_B_DEF:![0-9]+]]
77// BOTH: [[VBASE_B_DEF]] = !{[[VBASE_A_IN_B:![0-9]+]],
78//
79// Look for the vbtable offset of A, which should be 4 for MSVC, 24 otherwise.
80// BOTH: [[VBASE_A_IN_B]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[VBASE_B]],
81// BOTH-SAME:                              baseType: ![[VBASE_A:[0-9]+]],
82// MSVC-SAME:                              offset: 4,
83// CHECK-SAME:                             offset: 24,
84//
85// BOTH: ![[VBASE_A]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "A",
86
87  void f() {
88    B b;
89  }
90}
91
92namespace b5249287 {
93template <typename T> class A {
94  struct B;
95};
96
97class Cls {
98  template <typename T> friend class A<T>::B;
99};
100
101Cls obj;
102}
103
104// CHECK: [[FUNC:[0-9]+]] = distinct !DISubprogram(name: "func", linkageName: "_ZN7pr147634funcENS_3fooE"
105// CHECK-SAME:                                      type: {{![0-9]+}}
106// CHECK-SAME:                                      DISPFlagDefinition
107
108// CHECK: [[PR14763:![0-9]+]] = !DINamespace(name: "pr14763"
109namespace pr14763 {
110struct foo {
111// CHECK: ![[FOO:[0-9]+]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "foo"
112// CHECK-SAME:             scope: [[PR14763]]
113// CHECK-SAME:             identifier:
114  foo(const foo&);
115};
116
117// For some reason function arguments ended up down here
118// CHECK: ![[F]] = !DILocalVariable(name: "f", arg: 1, scope: ![[FUNC]]
119// CHECK-SAME:                      type: ![[FOO]]
120foo func(foo f) {
121  return f; // reference 'f' for now because otherwise we hit another bug
122}
123
124}
125
126void foo() {
127// CHECK: !DILocalVariable(name: "c"
128// CHECK-NOT:              arg:
129// CHECK-SAME:            )
130  const wchar_t c = L'x';
131  wchar_t d = c;
132}
133
134namespace pr9608 { // also pr9600
135struct incomplete;
136incomplete (*x)[3];
137}
138
139namespace pr16214 {
140// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "a"
141// CHECK-SAME:             elements: [[A_MEM:![0-9]+]]
142// CHECK-SAME:             identifier: "_ZTSN7pr162141aE"
143// CHECK: [[A_MEM]] = !{[[A_I:![0-9]*]]}
144struct a {
145// CHECK: [[A_I]] = !DIDerivedType(tag: DW_TAG_member, name: "i"
146  int i;
147};
148
149typedef a at;
150
151// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "b"
152// CHECK-SAME:             DIFlagFwdDecl
153struct b {
154};
155
156typedef b bt;
157
158void func() {
159  at a_inst;
160  bt *b_ptr_inst;
161  const bt *b_cnst_ptr_inst;
162}
163
164}
165