xref: /llvm-project/llvm/test/DebugInfo/X86/dbg-declare-arg.ll (revision 10b03e66629aedad79a804e22d23b575077303b3)
1; RUN: llc -O0 -fast-isel=true  -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
2; RUN: llc --try-experimental-debuginfo-iterators -O0 -fast-isel=true  -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5target triple = "x86_64-apple-macosx10.6.7"
6; rdar://problem/9321650
7
8; C++ source:
9; class A { public: int x; int y; int z; int o; ~A() { x = 1; }};
10;
11; A foo(int i) {
12;   int j = 0;
13;   if (i == 42) {
14;     j = i + 1;
15;   };
16;   A my_a;
17;   my_a.x = j;
18;   return my_a;
19; }
20
21; CHECK: DW_AT_name {{.*}}"j"
22; CHECK: DW_TAG_variable
23; CHECK-NEXT:   DW_AT_location [DW_FORM_sec_offset] (
24; CHECK-NEXT:     [0x{{.*}}, 0x{{.*}}): DW_OP_breg7 RSP+8, DW_OP_deref)
25; CHECK-NEXT:   DW_AT_name {{.*}}"my_a"
26
27%class.A = type { i32, i32, i32, i32 }
28
29define void @_Z3fooi(ptr sret(%class.A) %agg.result, i32 %i) ssp !dbg !19 {
30entry:
31  %i.addr = alloca i32, align 4
32  %j = alloca i32, align 4
33  %nrvo = alloca i1
34  %cleanup.dest.slot = alloca i32
35  store i32 %i, ptr %i.addr, align 4
36  call void @llvm.dbg.declare(metadata ptr %i.addr, metadata !26, metadata !DIExpression()), !dbg !27
37  call void @llvm.dbg.declare(metadata ptr %j, metadata !28, metadata !DIExpression()), !dbg !30
38  store i32 0, ptr %j, align 4, !dbg !31
39  %tmp = load i32, ptr %i.addr, align 4, !dbg !32
40  %cmp = icmp eq i32 %tmp, 42, !dbg !32
41  br i1 %cmp, label %if.then, label %if.end, !dbg !32
42
43if.then:                                          ; preds = %entry
44  %tmp1 = load i32, ptr %i.addr, align 4, !dbg !33
45  %add = add nsw i32 %tmp1, 1, !dbg !33
46  store i32 %add, ptr %j, align 4, !dbg !33
47  br label %if.end, !dbg !35
48
49if.end:                                           ; preds = %if.then, %entry
50  store i1 false, ptr %nrvo, !dbg !36
51  call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !37, metadata !DIExpression()), !dbg !39
52  %tmp2 = load i32, ptr %j, align 4, !dbg !40
53  store i32 %tmp2, ptr %agg.result, align 4, !dbg !40
54  store i1 true, ptr %nrvo, !dbg !41
55  store i32 1, ptr %cleanup.dest.slot
56  %nrvo.val = load i1, ptr %nrvo, !dbg !42
57  br i1 %nrvo.val, label %nrvo.skipdtor, label %nrvo.unused, !dbg !42
58
59nrvo.unused:                                      ; preds = %if.end
60  call void @_ZN1AD1Ev(ptr %agg.result), !dbg !42
61  br label %nrvo.skipdtor, !dbg !42
62
63nrvo.skipdtor:                                    ; preds = %nrvo.unused, %if.end
64  ret void, !dbg !42
65}
66
67declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
68
69define linkonce_odr void @_ZN1AD1Ev(ptr %this) unnamed_addr ssp align 2 !dbg !22 {
70entry:
71  %this.addr = alloca ptr, align 8
72  store ptr %this, ptr %this.addr, align 8
73  call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !43, metadata !DIExpression()), !dbg !44
74  %this1 = load ptr, ptr %this.addr
75  call void @_ZN1AD2Ev(ptr %this1), !dbg !53
76  ret void, !dbg !45
77}
78
79define linkonce_odr void @_ZN1AD2Ev(ptr %this) unnamed_addr nounwind ssp align 2 !dbg !25 {
80entry:
81  %this.addr = alloca ptr, align 8
82  store ptr %this, ptr %this.addr, align 8
83  call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !46, metadata !DIExpression()), !dbg !47
84  %this1 = load ptr, ptr %this.addr
85  store i32 1, ptr %this1, align 4, !dbg !48
86  ret void, !dbg !48
87}
88
89!llvm.dbg.cu = !{!2}
90!llvm.module.flags = !{!52}
91
92!0 = !DISubprogram(name: "~A", line: 2, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, file: !51, scope: !1, type: !11)
93!1 = !DICompositeType(tag: DW_TAG_class_type, name: "A", line: 2, size: 128, align: 32, file: !51, scope: !2, elements: !4)
94!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.0 (trunk 130127)", isOptimized: false, emissionKind: FullDebug, file: !51, enums: !{}, retainedTypes: !{})
95!3 = !DIFile(filename: "a.cc", directory: "/private/tmp")
96!4 = !{!5, !7, !8, !9, !0, !10, !14}
97!5 = !DIDerivedType(tag: DW_TAG_member, name: "x", line: 2, size: 32, align: 32, file: !51, scope: !3, baseType: !6)
98!6 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
99!7 = !DIDerivedType(tag: DW_TAG_member, name: "y", line: 2, size: 32, align: 32, offset: 32, file: !51, scope: !3, baseType: !6)
100!8 = !DIDerivedType(tag: DW_TAG_member, name: "z", line: 2, size: 32, align: 32, offset: 64, file: !51, scope: !3, baseType: !6)
101!9 = !DIDerivedType(tag: DW_TAG_member, name: "o", line: 2, size: 32, align: 32, offset: 96, file: !51, scope: !3, baseType: !6)
102!10 = !DISubprogram(name: "A", line: 2, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, file: !51, scope: !1, type: !11)
103!11 = !DISubroutineType(types: !12)
104!12 = !{null, !13}
105!13 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial, file: !3, baseType: !1)
106!14 = !DISubprogram(name: "A", line: 2, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, file: !51, scope: !1, type: !15)
107!15 = !DISubroutineType(types: !16)
108!16 = !{null, !13, !17}
109!17 = !DIDerivedType(tag: DW_TAG_reference_type, scope: !2, baseType: !18)
110!18 = !DIDerivedType(tag: DW_TAG_const_type, file: !3, baseType: !1)
111!19 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !51, scope: !3, type: !20)
112!20 = !DISubroutineType(types: !21)
113!21 = !{!1}
114!22 = distinct !DISubprogram(name: "~A", linkageName: "_ZN1AD1Ev", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !51, scope: !3, type: !23)
115!23 = !DISubroutineType(types: !24)
116!24 = !{null}
117!25 = distinct !DISubprogram(name: "~A", linkageName: "_ZN1AD2Ev", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !51, scope: !3, type: !23)
118!26 = !DILocalVariable(name: "i", line: 4, arg: 1, scope: !19, file: !3, type: !6)
119!27 = !DILocation(line: 4, column: 11, scope: !19)
120!28 = !DILocalVariable(name: "j", line: 5, scope: !29, file: !3, type: !6)
121!29 = distinct !DILexicalBlock(line: 4, column: 14, file: !51, scope: !19)
122!30 = !DILocation(line: 5, column: 7, scope: !29)
123!31 = !DILocation(line: 5, column: 12, scope: !29)
124!32 = !DILocation(line: 6, column: 3, scope: !29)
125!33 = !DILocation(line: 7, column: 5, scope: !34)
126!34 = distinct !DILexicalBlock(line: 6, column: 16, file: !51, scope: !29)
127!35 = !DILocation(line: 8, column: 3, scope: !34)
128!36 = !DILocation(line: 9, column: 9, scope: !29)
129!37 = !DILocalVariable(name: "my_a", line: 9, scope: !29, file: !3, type: !38)
130!38 = !DIDerivedType(tag: DW_TAG_reference_type, file: !3, baseType: !1)
131!39 = !DILocation(line: 9, column: 5, scope: !29)
132!40 = !DILocation(line: 10, column: 3, scope: !29)
133!41 = !DILocation(line: 11, column: 3, scope: !29)
134!42 = !DILocation(line: 12, column: 1, scope: !29)
135!43 = !DILocalVariable(name: "this", line: 2, arg: 1, flags: DIFlagArtificial, scope: !22, file: !3, type: !13)
136!44 = !DILocation(line: 2, column: 47, scope: !22)
137!45 = !DILocation(line: 2, column: 61, scope: !22)
138!46 = !DILocalVariable(name: "this", line: 2, arg: 1, flags: DIFlagArtificial, scope: !25, file: !3, type: !13)
139!47 = !DILocation(line: 2, column: 47, scope: !25)
140!48 = !DILocation(line: 2, column: 54, scope: !49)
141!49 = distinct !DILexicalBlock(line: 2, column: 52, file: !51, scope: !25)
142!51 = !DIFile(filename: "a.cc", directory: "/private/tmp")
143!52 = !{i32 1, !"Debug Info Version", i32 3}
144!53 = !DILocation(line: 0, scope: !22)
145