xref: /llvm-project/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll (revision fc1270dd2972b5302ff8717d7dcf754c22bbddc3)
1; Test that coverage instrumentation does not lose debug location.
2
3; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -S | FileCheck %s
4
5; C++ source:
6; 1: struct A {
7; 2:  int f();
8; 3:  int x;
9; 4: };
10; 5:
11; 6: int A::f() {
12; 7:    return x;
13; 8: }
14; clang++ ../1.cc -O3 -g -S -emit-llvm  -fno-strict-aliasing
15; and add sanitize_address to @_ZN1A1fEv
16
17; Test that __sanitizer_cov_trace_pc_guard call has !dbg pointing to the opening { of A::f().
18; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr{{.*}}) #{{.*}}, !dbg [[A:!.*]]
19; CHECK: [[A]] = !DILocation(line: 6, scope: !{{.*}})
20
21
22target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23target triple = "x86_64-unknown-linux-gnu"
24
25%struct.A = type { i32 }
26
27; Function Attrs: nounwind readonly uwtable
28define i32 @_ZN1A1fEv(ptr nocapture readonly %this) #0 align 2 !dbg !13 {
29entry:
30  tail call void @llvm.dbg.value(metadata ptr %this, i64 0, metadata !15, metadata !DIExpression()), !dbg !20
31  %0 = load i32, ptr %this, align 4, !dbg !21
32  ret i32 %0, !dbg !21
33}
34
35; Function Attrs: nounwind readnone
36declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
37
38attributes #0 = { sanitize_address nounwind readonly uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
39attributes #1 = { nounwind readnone }
40
41!llvm.dbg.cu = !{!0}
42!llvm.module.flags = !{!17, !18}
43!llvm.ident = !{!19}
44
45!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (210251)", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !3, globals: !2, imports: !2)
46!1 = !DIFile(filename: "../1.cc", directory: "/code/llvm/build0")
47!2 = !{}
48!3 = !{!4}
49!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", line: 1, size: 32, align: 32, file: !1, elements: !5, identifier: "_ZTS1A")
50!5 = !{!6, !8}
51!6 = !DIDerivedType(tag: DW_TAG_member, name: "x", line: 3, size: 32, align: 32, file: !1, scope: !4, baseType: !7)
52!7 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
53!8 = !DISubprogram(name: "f", linkageName: "_ZN1A1fEv", line: 2, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 2, file: !1, scope: !4, type: !9)
54!9 = !DISubroutineType(types: !10)
55!10 = !{!7, !11}
56!11 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !4)
57!13 = distinct !DISubprogram(name: "f", linkageName: "_ZN1A1fEv", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 6, file: !1, scope: !4, type: !9, declaration: !8, retainedNodes: !14)
58!14 = !{!15}
59!15 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !13, type: !16)
60!16 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !4)
61!17 = !{i32 2, !"Dwarf Version", i32 4}
62!18 = !{i32 2, !"Debug Info Version", i32 3}
63!19 = !{!"clang version 3.5.0 (210251)"}
64!20 = !DILocation(line: 0, scope: !13)
65!21 = !DILocation(line: 7, scope: !13)
66