1 // 1) Compile shared code into different object files and into an executable. 2 3 // RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %s -c -o %t.v1.o \ 4 // RUN: -D_VERSION_1 5 // RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %s -c -o %t.v2.o \ 6 // RUN: -D_VERSION_2 7 // RUN: %clangxx_profgen -std=c++14 -fcoverage-mapping %t.v1.o %t.v2.o \ 8 // RUN: -o %t.exe 9 10 // 2) Collect profile data. 11 12 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe 13 // RUN: llvm-profdata merge %t.profraw -o %t.profdata 14 15 // 3) Generate coverage reports from the different object files and the exe. 16 17 // RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY 18 // RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY 19 // RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2 20 // RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2 21 22 // 4) Verify that coverage reporting on the aggregate coverage mapping shows 23 // hits for all code. (We used to arbitrarily pick a mapping from one binary 24 // and prefer it over others.) When only limited coverage information is 25 // available (just from one binary), don't try to guess any region counts. 26 27 struct A { 28 A() {} // V1: [[@LINE]]{{ *}}|{{ *}}1 29 // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}| 30 A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}| 31 // V2: [[@LINE-1]]{{ *}}|{{ *}}1 32 }; 33 34 #ifdef _VERSION_1 35 36 void foo(); 37 38 void bar() { 39 A x; // V1: [[@LINE]]{{ *}}|{{ *}}1 40 } 41 42 int main() { 43 foo(); // V1: [[@LINE]]{{ *}}|{{ *}}1 44 bar(); 45 return 0; 46 } 47 48 #endif // _VERSION_1 49 50 #ifdef _VERSION_2 51 52 void foo() { 53 A x{0}; // V2: [[@LINE]]{{ *}}|{{ *}}1 54 } 55 56 #endif // _VERSION_2 57