| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 1 | ; RUN: llc %s -filetype=obj -O0 -mtriple=i386-unknown-linux-gnu -dwarf-version=4 -o %t | 
|  | 2 | ; RUN: llvm-dwarfdump %t | FileCheck %s | 
|  | 3 |  | 
|  | 4 | ; From the code: | 
|  | 5 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 6 | ; debug-loc-offset1.cc | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 7 | ; int bar (int b) { | 
|  | 8 | ;   return b+4; | 
|  | 9 | ; } | 
|  | 10 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 11 | ; debug-loc-offset2.cc | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 12 | ; struct A { | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 13 | ;   int var; | 
|  | 14 | ;   virtual char foo(); | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 15 | ; }; | 
|  | 16 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 17 | ; void baz(struct A a) { | 
|  | 18 | ;   int z = 2; | 
|  | 19 | ;   if (a.var > 2) | 
|  | 20 | ;     z++; | 
|  | 21 | ;   if (a.foo() == 'a') | 
|  | 22 | ;     z++; | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 23 | ; } | 
|  | 24 |  | 
|  | 25 | ; Compiled separately for i386-pc-linux-gnu and linked together. | 
|  | 26 | ; This ensures that we have multiple compile units so that we can verify that | 
|  | 27 | ; debug_loc entries are relative to the low_pc of the CU. The loc entry for | 
|  | 28 | ; the byval argument in foo.cpp is in the second CU and so should have | 
|  | 29 | ; an offset relative to that CU rather than from the beginning of the text | 
|  | 30 | ; section. | 
|  | 31 |  | 
|  | 32 | ; Checking that we have two compile units with two sets of high/lo_pc. | 
|  | 33 | ; CHECK: .debug_info contents | 
|  | 34 | ; CHECK: DW_TAG_compile_unit | 
|  | 35 | ; CHECK: DW_AT_low_pc | 
|  | 36 | ; CHECK: DW_AT_high_pc | 
|  | 37 |  | 
|  | 38 | ; CHECK: DW_TAG_compile_unit | 
|  | 39 | ; CHECK: DW_AT_low_pc | 
|  | 40 | ; CHECK: DW_AT_high_pc | 
|  | 41 |  | 
|  | 42 | ; CHECK: DW_TAG_subprogram | 
| David Blaikie | 2f75351 | 2014-05-23 21:11:46 +0000 | [diff] [blame] | 43 | ; CHECK-NOT: DW_TAG | 
| Paul Robinson | 857b443 | 2015-03-10 22:44:45 +0000 | [diff] [blame] | 44 | ; CHECK: DW_AT_linkage_name [DW_FORM_strp]{{.*}}"_Z3baz1A" | 
| David Blaikie | 2f75351 | 2014-05-23 21:11:46 +0000 | [diff] [blame] | 45 | ; CHECK-NOT: {{DW_TAG|NULL}} | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 46 | ; CHECK: DW_TAG_formal_parameter | 
| David Blaikie | eb1a272 | 2014-06-13 22:18:23 +0000 | [diff] [blame] | 47 | ; CHECK-NOT: DW_TAG | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 48 | ; CHECK: DW_AT_location [DW_FORM_sec_offset]   (0x00000000) | 
| David Blaikie | eb1a272 | 2014-06-13 22:18:23 +0000 | [diff] [blame] | 49 | ; CHECK-NOT: DW_TAG | 
|  | 50 | ; CHECK: DW_AT_name [DW_FORM_strp]{{.*}}"a" | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | ; CHECK: DW_TAG_variable | 
|  | 53 | ; CHECK: DW_AT_location [DW_FORM_exprloc] | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 54 | ; CHECK-NOT: DW_AT_location | 
|  | 55 |  | 
|  | 56 | ; CHECK: .debug_loc contents: | 
|  | 57 | ; CHECK: 0x00000000: Beginning address offset: 0x0000000000000000 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 58 | ; CHECK:                Ending address offset: 0x000000000000001a | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 59 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 60 | %struct.A = type { i32 (...)**, i32 } | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 61 |  | 
|  | 62 | ; Function Attrs: nounwind | 
|  | 63 | define i32 @_Z3bari(i32 %b) #0 { | 
|  | 64 | entry: | 
|  | 65 | %b.addr = alloca i32, align 4 | 
|  | 66 | store i32 %b, i32* %b.addr, align 4 | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 67 | call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !21, metadata !MDExpression()), !dbg !22 | 
| David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 68 | %0 = load i32, i32* %b.addr, align 4, !dbg !23 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 69 | %add = add nsw i32 %0, 4, !dbg !23 | 
|  | 70 | ret i32 %add, !dbg !23 | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
|  | 73 | ; Function Attrs: nounwind readnone | 
| Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 74 | declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 75 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 76 | define void @_Z3baz1A(%struct.A* %a) #2 { | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 77 | entry: | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 78 | %z = alloca i32, align 4 | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 79 | call void @llvm.dbg.declare(metadata %struct.A* %a, metadata !24, metadata !MDExpression(DW_OP_deref)), !dbg !25 | 
|  | 80 | call void @llvm.dbg.declare(metadata i32* %z, metadata !26, metadata !MDExpression()), !dbg !27 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 81 | store i32 2, i32* %z, align 4, !dbg !27 | 
| David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 82 | %var = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1, !dbg !28 | 
| David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 83 | %0 = load i32, i32* %var, align 4, !dbg !28 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 84 | %cmp = icmp sgt i32 %0, 2, !dbg !28 | 
|  | 85 | br i1 %cmp, label %if.then, label %if.end, !dbg !28 | 
|  | 86 |  | 
|  | 87 | if.then:                                          ; preds = %entry | 
| David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 88 | %1 = load i32, i32* %z, align 4, !dbg !30 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 89 | %inc = add nsw i32 %1, 1, !dbg !30 | 
|  | 90 | store i32 %inc, i32* %z, align 4, !dbg !30 | 
|  | 91 | br label %if.end, !dbg !30 | 
|  | 92 |  | 
|  | 93 | if.end:                                           ; preds = %if.then, %entry | 
|  | 94 | %call = call signext i8 @_ZN1A3fooEv(%struct.A* %a), !dbg !31 | 
|  | 95 | %conv = sext i8 %call to i32, !dbg !31 | 
|  | 96 | %cmp1 = icmp eq i32 %conv, 97, !dbg !31 | 
|  | 97 | br i1 %cmp1, label %if.then2, label %if.end4, !dbg !31 | 
|  | 98 |  | 
|  | 99 | if.then2:                                         ; preds = %if.end | 
| David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 100 | %2 = load i32, i32* %z, align 4, !dbg !33 | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 101 | %inc3 = add nsw i32 %2, 1, !dbg !33 | 
|  | 102 | store i32 %inc3, i32* %z, align 4, !dbg !33 | 
|  | 103 | br label %if.end4, !dbg !33 | 
|  | 104 |  | 
|  | 105 | if.end4:                                          ; preds = %if.then2, %if.end | 
|  | 106 | ret void, !dbg !34 | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 109 | declare signext i8 @_ZN1A3fooEv(%struct.A*) #2 | 
|  | 110 |  | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 111 | attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | 
|  | 112 | attributes #1 = { nounwind readnone } | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 113 | attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 114 |  | 
|  | 115 | !llvm.dbg.cu = !{!0, !9} | 
| Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 116 | !llvm.module.flags = !{!18, !19} | 
|  | 117 | !llvm.ident = !{!20, !20} | 
| Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 118 |  | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 119 | !0 = !MDCompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (210479)", isOptimized: false, emissionKind: 1, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2) | 
|  | 120 | !1 = !MDFile(filename: "debug-loc-offset1.cc", directory: "/llvm_cmake_gcc") | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 121 | !2 = !{} | 
|  | 122 | !3 = !{!4} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 123 | !4 = !MDSubprogram(name: "bar", linkageName: "_Z3bari", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 1, file: !1, scope: !5, type: !6, function: i32 (i32)* @_Z3bari, variables: !2) | 
|  | 124 | !5 = !MDFile(filename: "debug-loc-offset1.cc", directory: "/llvm_cmake_gcc") | 
|  | 125 | !6 = !MDSubroutineType(types: !7) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 126 | !7 = !{!8, !8} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 127 | !8 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) | 
|  | 128 | !9 = !MDCompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (210479)", isOptimized: false, emissionKind: 1, file: !10, enums: !2, retainedTypes: !11, subprograms: !13, globals: !2, imports: !2) | 
|  | 129 | !10 = !MDFile(filename: "debug-loc-offset2.cc", directory: "/llvm_cmake_gcc") | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 130 | !11 = !{!12} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 131 | !12 = !MDCompositeType(tag: DW_TAG_structure_type, name: "A", line: 1, flags: DIFlagFwdDecl, file: !10, identifier: "_ZTS1A") | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 132 | !13 = !{!14} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 133 | !14 = !MDSubprogram(name: "baz", linkageName: "_Z3baz1A", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 6, file: !10, scope: !15, type: !16, function: void (%struct.A*)* @_Z3baz1A, variables: !2) | 
|  | 134 | !15 = !MDFile(filename: "debug-loc-offset2.cc", directory: "/llvm_cmake_gcc") | 
|  | 135 | !16 = !MDSubroutineType(types: !17) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 136 | !17 = !{null, !12} | 
|  | 137 | !18 = !{i32 2, !"Dwarf Version", i32 4} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 138 | !19 = !{i32 2, !"Debug Info Version", i32 3} | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 139 | !20 = !{!"clang version 3.5.0 (210479)"} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 140 | !21 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "b", line: 1, arg: 1, scope: !4, file: !5, type: !8) | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 141 | !22 = !MDLocation(line: 1, scope: !4) | 
|  | 142 | !23 = !MDLocation(line: 2, scope: !4) | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 143 | !24 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "a", line: 6, arg: 1, scope: !14, file: !15, type: !"_ZTS1A") | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 144 | !25 = !MDLocation(line: 6, scope: !14) | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 145 | !26 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "z", line: 7, scope: !14, file: !15, type: !8) | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 146 | !27 = !MDLocation(line: 7, scope: !14) | 
|  | 147 | !28 = !MDLocation(line: 8, scope: !29) | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 148 | !29 = distinct !MDLexicalBlock(line: 8, column: 0, file: !10, scope: !14) | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 149 | !30 = !MDLocation(line: 9, scope: !29) | 
|  | 150 | !31 = !MDLocation(line: 10, scope: !32) | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 151 | !32 = distinct !MDLexicalBlock(line: 10, column: 0, file: !10, scope: !14) | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 152 | !33 = !MDLocation(line: 11, scope: !32) | 
|  | 153 | !34 = !MDLocation(line: 12, scope: !14) |