1*9880d681SAndroid Build Coastguard Worker; Test that coverage instrumentation does not lose debug location. 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker; C++ source: 6*9880d681SAndroid Build Coastguard Worker; 1: void foo(int *a) { 7*9880d681SAndroid Build Coastguard Worker; 2: if (a) 8*9880d681SAndroid Build Coastguard Worker; 3: *a = 0; 9*9880d681SAndroid Build Coastguard Worker; 4: } 10*9880d681SAndroid Build Coastguard Worker; clang++ if.cc -O3 -g -S -emit-llvm 11*9880d681SAndroid Build Coastguard Worker; and add sanitize_address to @_Z3fooPi 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 15*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu" 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker; Check that __sanitizer_cov call has !dgb pointing to the beginning 18*9880d681SAndroid Build Coastguard Worker; of appropriate basic blocks. 19*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL:_Z3fooPi 20*9880d681SAndroid Build Coastguard Worker; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[A:!.*]] 21*9880d681SAndroid Build Coastguard Worker; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[B:!.*]] 22*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 23*9880d681SAndroid Build Coastguard Worker; CHECK: [[A]] = !DILocation(line: 1, scope: !{{.*}}) 24*9880d681SAndroid Build Coastguard Worker; CHECK: [[B]] = !DILocation(line: 3, column: 5, scope: !{{.*}}) 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Workerdefine void @_Z3fooPi(i32* %a) #0 !dbg !4 { 27*9880d681SAndroid Build Coastguard Workerentry: 28*9880d681SAndroid Build Coastguard Worker tail call void @llvm.dbg.value(metadata i32* %a, i64 0, metadata !11, metadata !DIExpression()), !dbg !15 29*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32* %a, null, !dbg !16 30*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.end, label %if.then, !dbg !16 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 33*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %a, align 4, !dbg !18, !tbaa !19 34*9880d681SAndroid Build Coastguard Worker br label %if.end, !dbg !18 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %entry, %if.then 37*9880d681SAndroid Build Coastguard Worker ret void, !dbg !23 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone 41*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Workerattributes #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} 44*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone } 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0} 47*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!12, !13} 48*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!14} 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 (217079)", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 51*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "if.cc", directory: "FOO") 52*9880d681SAndroid Build Coastguard Worker!2 = !{} 53*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooPi", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, variables: !10) 54*9880d681SAndroid Build Coastguard Worker!5 = !DIFile(filename: "if.cc", directory: "FOO") 55*9880d681SAndroid Build Coastguard Worker!6 = !DISubroutineType(types: !7) 56*9880d681SAndroid Build Coastguard Worker!7 = !{null, !8} 57*9880d681SAndroid Build Coastguard Worker!8 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !9) 58*9880d681SAndroid Build Coastguard Worker!9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 59*9880d681SAndroid Build Coastguard Worker!10 = !{!11} 60*9880d681SAndroid Build Coastguard Worker!11 = !DILocalVariable(name: "a", line: 1, arg: 1, scope: !4, file: !5, type: !8) 61*9880d681SAndroid Build Coastguard Worker!12 = !{i32 2, !"Dwarf Version", i32 4} 62*9880d681SAndroid Build Coastguard Worker!13 = !{i32 2, !"Debug Info Version", i32 3} 63*9880d681SAndroid Build Coastguard Worker!14 = !{!"clang version 3.6.0 (217079)"} 64*9880d681SAndroid Build Coastguard Worker!15 = !DILocation(line: 1, column: 15, scope: !4) 65*9880d681SAndroid Build Coastguard Worker!16 = !DILocation(line: 2, column: 7, scope: !17) 66*9880d681SAndroid Build Coastguard Worker!17 = distinct !DILexicalBlock(line: 2, column: 7, file: !1, scope: !4) 67*9880d681SAndroid Build Coastguard Worker!18 = !DILocation(line: 3, column: 5, scope: !17) 68*9880d681SAndroid Build Coastguard Worker!19 = !{!20, !20, i64 0} 69*9880d681SAndroid Build Coastguard Worker!20 = !{!"int", !21, i64 0} 70*9880d681SAndroid Build Coastguard Worker!21 = !{!"omnipotent char", !22, i64 0} 71*9880d681SAndroid Build Coastguard Worker!22 = !{!"Simple C/C++ TBAA"} 72*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 4, column: 1, scope: !4) 73