1; RUN: opt -passes='module(sancov-module)' -sanitizer-coverage-trace-pc \
2; RUN: -sanitizer-coverage-level=3 %s -S -o - | FileCheck %s
3
4; The edge between %entry and %for.inc.i is a critical edge.
5; ModuleSanitizerCoveragePass must split this critical edge in order to track
6; coverage of this edge. ModuleSanitizerCoveragePass will also insert calls to
7; @__sanitizer_cov_trace_pc using the debug location from the predecessor's
8; branch.  but, if the branch itself is missing debug info (say, by accident
9; due to a bug in an earlier transform), we would fail a verifier check that
10; verifies calls to functions with debug info themselves have debug info.
11; The definition of @__sanitizer_cov_trace_pc may be visible during LTO.
12
13; Of the below checks, we really only care that the calls to
14; @__sanitizer_cov_trace_pc retain !dbg metadata.
15
16define void @update_shadow() !dbg !3 {
17; CHECK-LABEL: @update_shadow(
18; CHECK-NEXT:  entry:
19; CHECK-NEXT:    call void @__sanitizer_cov_trace_pc() #[[ATTR0:[0-9]+]], !dbg [[DBG6:![0-9]+]]
20; CHECK:       entry.for.inc.i_crit_edge:
21; CHECK-NEXT:    call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG7:![0-9]+]]
22; CHECK:       if.end22.i:
23; CHECK-NEXT:    call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG8:![0-9]+]]
24; CHECK:       [[DBG6]] = !DILocation(line: 192, scope: !3)
25; CHECK:       [[DBG7]] = !DILocation(line: 0, scope: !3)
26; CHECK:       [[DBG8]] = !DILocation(line: 129, column: 2, scope: !3)
27entry:
28  br i1 undef, label %for.inc.i, label %if.end22.i
29
30if.end22.i:                                       ; preds = %entry
31  br label %for.inc.i, !dbg !8
32
33for.inc.i:                                        ; preds = %if.end22.i, %entry
34  ret void, !dbg !6
35}
36
37define void @__sanitizer_cov_trace_pc() !dbg !7{
38  ret void
39}
40
41!llvm.dbg.cu = !{!0}
42!llvm.module.flags = !{!2}
43
44!0 = distinct !DICompileUnit(language: DW_LANG_C89, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
45!1 = !DIFile(filename: "kernel/cfi.c", directory: "")
46!2 = !{i32 2, !"Debug Info Version", i32 3}
47!3 = distinct !DISubprogram(name: "update_shadow", scope: !1, file: !1, line: 190, type: !4, scopeLine: 192, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
48!4 = !DISubroutineType(types: !5)
49!5 = !{}
50!6 = !DILocation(line: 223, column: 1, scope: !3)
51!7 = distinct !DISubprogram(name: "__sanitizer_cov_trace_pc", scope: !1, file: !1, line: 200, type: !4, scopeLine: 200, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
52!8 = !DILocation(line: 129, column: 2, scope: !3)
53