xref: /llvm-project/clang/test/CodeGenCXX/debug-info-structured-binding.cpp (revision 310a9f3f257f1f7a41958b792b27e69a0237218f)
1 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg.declare"
2 
3 // CHECK: #dbg_declare(ptr %{{[a-z]+}}, ![[VAR_0:[0-9]+]], !DIExpression(),
4 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_1:[0-9]+]], !DIExpression(),
5 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_2:[0-9]+]], !DIExpression(DW_OP_plus_uconst, 4),
6 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_3:[0-9]+]], !DIExpression(DW_OP_deref),
7 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_4:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 4),
8 // CHECK: #dbg_declare(ptr %z1, ![[VAR_5:[0-9]+]], !DIExpression()
9 // CHECK: #dbg_declare(ptr %z2, ![[VAR_6:[0-9]+]], !DIExpression()
10 // CHECK: ![[VAR_0]] = !DILocalVariable(name: "a"
11 // CHECK: ![[VAR_1]] = !DILocalVariable(name: "x1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
12 // CHECK: ![[VAR_2]] = !DILocalVariable(name: "y1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
13 // CHECK: ![[VAR_3]] = !DILocalVariable(name: "x2", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
14 // CHECK: ![[VAR_4]] = !DILocalVariable(name: "y2", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
15 // CHECK: ![[VAR_5]] = !DILocalVariable(name: "z1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
16 // CHECK: ![[VAR_6]] = !DILocalVariable(name: "z2", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
17 
18 struct A {
19   int x;
20   int y;
21 };
22 
23 struct B {
24   int w;
25   int z;
26   template<int> int get();
27   template<> int get<0>() { return w; }
28   template<> int get<1>() { return z; }
29 };
30 
31 // Note: the following declarations are necessary for decomposition of tuple-like
32 // structured bindings
33 namespace std {
34 template<typename T> struct tuple_size {
35 };
36 template<>
37 struct tuple_size<B> {
38     static constexpr unsigned value = 2;
39 };
40 
41 template<unsigned, typename T> struct tuple_element { using type = int; };
42 } // namespace std
43 
44 int f() {
45   A a{10, 20};
46   auto [x1, y1] = a;
47   auto &[x2, y2] = a;
48   auto [z1, z2] = B{1, 2};
49   return x1 + y1 + x2 + y2 + z1 + z2;
50 }
51