| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 1 | ; Test that coverage instrumentation does not lose debug location. | 
|  | 2 |  | 
| Kostya Serebryany | 29a18dc | 2014-11-11 22:14:37 +0000 | [diff] [blame] | 3 | ; RUN: opt < %s -sancov  -sanitizer-coverage-level=2 -S | FileCheck %s | 
| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 4 |  | 
|  | 5 | ; C++ source: | 
|  | 6 | ; 1: void foo(int *a) { | 
|  | 7 | ; 2:     if (a) | 
|  | 8 | ; 3:         *a = 0; | 
|  | 9 | ; 4: } | 
|  | 10 | ; clang++ if.cc -O3 -g -S -emit-llvm | 
|  | 11 | ; and add sanitize_address to @_Z3fooPi | 
|  | 12 |  | 
|  | 13 |  | 
|  | 14 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | 
|  | 15 | target triple = "x86_64-unknown-linux-gnu" | 
|  | 16 |  | 
|  | 17 | ; Check that __sanitizer_cov call has !dgb pointing to the beginning | 
|  | 18 | ; of appropriate basic blocks. | 
|  | 19 | ; CHECK-LABEL:_Z3fooPi | 
| Kostya Serebryany | 9fdeb37 | 2014-12-23 22:32:17 +0000 | [diff] [blame] | 20 | ; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[A:!.*]] | 
|  | 21 | ; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[B:!.*]] | 
|  | 22 | ; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[C:!.*]] | 
| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 23 | ; CHECK: ret void | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 24 | ; CHECK: [[A]] = !MDLocation(line: 1, scope: !{{.*}}) | 
|  | 25 | ; CHECK: [[B]] = !MDLocation(line: 3, column: 5, scope: !{{.*}}) | 
|  | 26 | ; CHECK: [[C]] = !MDLocation(line: 4, column: 1, scope: !{{.*}}) | 
| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 27 |  | 
|  | 28 | define void @_Z3fooPi(i32* %a) #0 { | 
|  | 29 | entry: | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 30 | tail call void @llvm.dbg.value(metadata i32* %a, i64 0, metadata !11, metadata !MDExpression()), !dbg !15 | 
| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 31 | %tobool = icmp eq i32* %a, null, !dbg !16 | 
|  | 32 | br i1 %tobool, label %if.end, label %if.then, !dbg !16 | 
|  | 33 |  | 
|  | 34 | if.then:                                          ; preds = %entry | 
|  | 35 | store i32 0, i32* %a, align 4, !dbg !18, !tbaa !19 | 
|  | 36 | br label %if.end, !dbg !18 | 
|  | 37 |  | 
|  | 38 | if.end:                                           ; preds = %entry, %if.then | 
|  | 39 | ret void, !dbg !23 | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | ; Function Attrs: nounwind readnone | 
| Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 43 | declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 | 
| Kostya Serebryany | 3175521 | 2014-09-03 23:24:18 +0000 | [diff] [blame] | 44 |  | 
|  | 45 | attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" sanitize_address} | 
|  | 46 | attributes #1 = { nounwind readnone } | 
|  | 47 |  | 
|  | 48 | !llvm.dbg.cu = !{!0} | 
|  | 49 | !llvm.module.flags = !{!12, !13} | 
|  | 50 | !llvm.ident = !{!14} | 
|  | 51 |  | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 52 | !0 = !MDCompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 (217079)", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2) | 
|  | 53 | !1 = !MDFile(filename: "if.cc", directory: "FOO") | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 54 | !2 = !{} | 
|  | 55 | !3 = !{!4} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 56 | !4 = !MDSubprogram(name: "foo", linkageName: "_Z3fooPi", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 1, file: !1, scope: !5, type: !6, function: void (i32*)* @_Z3fooPi, variables: !10) | 
|  | 57 | !5 = !MDFile(filename: "if.cc", directory: "FOO") | 
|  | 58 | !6 = !MDSubroutineType(types: !7) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 59 | !7 = !{null, !8} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 60 | !8 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !9) | 
|  | 61 | !9 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 62 | !10 = !{!11} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 63 | !11 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "a", line: 1, arg: 1, scope: !4, file: !5, type: !8) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 64 | !12 = !{i32 2, !"Dwarf Version", i32 4} | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 65 | !13 = !{i32 2, !"Debug Info Version", i32 3} | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 66 | !14 = !{!"clang version 3.6.0 (217079)"} | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 67 | !15 = !MDLocation(line: 1, column: 15, scope: !4) | 
|  | 68 | !16 = !MDLocation(line: 2, column: 7, scope: !17) | 
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 69 | !17 = distinct !MDLexicalBlock(line: 2, column: 7, file: !1, scope: !4) | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 70 | !18 = !MDLocation(line: 3, column: 5, scope: !17) | 
| Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 71 | !19 = !{!20, !20, i64 0} | 
|  | 72 | !20 = !{!"int", !21, i64 0} | 
|  | 73 | !21 = !{!"omnipotent char", !22, i64 0} | 
|  | 74 | !22 = !{!"Simple C/C++ TBAA"} | 
| Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 75 | !23 = !MDLocation(line: 4, column: 1, scope: !4) |