File: instrprof-merging.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (56 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 1) Compile shared code into different object files and into an executable.

// RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %s -c -o %t.v1.o \
// RUN:                  -D_VERSION_1
// RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %s -c -o %t.v2.o \
// RUN:                  -D_VERSION_2
// RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %t.v1.o %t.v2.o \
// RUN:                  -o %t.exe

// 2) Collect profile data.

// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
// RUN: llvm-profdata merge %t.profraw -o %t.profdata

// 3) Generate coverage reports from the different object files and the exe.

// RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY
// RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY
// RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
// RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2

// 4) Verify that coverage reporting on the aggregate coverage mapping shows
//    hits for all code. (We used to arbitrarily pick a mapping from one binary
//    and prefer it over others.) When only limited coverage information is
//    available (just from one binary), don't try to guess any region counts.

struct A {
  A() {}    // V1: [[@LINE]]{{ *}}|{{ *}}1
            // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}|
  A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}|
            // V2: [[@LINE-1]]{{ *}}|{{ *}}1
};

#ifdef _VERSION_1

void foo();

void bar() {
  A x;      // V1: [[@LINE]]{{ *}}|{{ *}}1
}

int main() {
  foo();    // V1: [[@LINE]]{{ *}}|{{ *}}1
  bar();
  return 0;
}

#endif // _VERSION_1

#ifdef _VERSION_2

void foo() {
  A x{0};   // V2: [[@LINE]]{{ *}}|{{ *}}1
}

#endif // _VERSION_2