[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / test / tools / llvm-cov / branch-macros.cpp
blob73042ac397d406984f73f515a1fb0e345171d861
1 // RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
2 // RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
3 // RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORT
5 #define COND1 (a == b)
6 #define COND2 (a != b)
7 #define COND3 (COND1 && COND2)
8 #define COND4 (COND3 ? COND2 : COND1)
9 #define MACRO1 COND3
10 #define MACRO2 MACRO1
11 #define MACRO3 MACRO2
13 #include <stdlib.h>
16 bool func(int a, int b) {
17 bool c = COND1 && COND2; // CHECK: | | | Branch ([[@LINE-12]]:15): [True: 1, False: 2]
18 // CHECK: | | | Branch ([[@LINE-12]]:15): [True: 0, False: 1]
19 bool d = COND3; // CHECK: | | | | | Branch ([[@LINE-14]]:15): [True: 1, False: 2]
20 // CHECK: | | | | | Branch ([[@LINE-14]]:15): [True: 0, False: 1]
21 bool e = MACRO1; // CHECK: | | | | | | | Branch ([[@LINE-16]]:15): [True: 1, False: 2]
22 // CHECK: | | | | | | | Branch ([[@LINE-16]]:15): [True: 0, False: 1]
23 bool f = MACRO2; // CHECK: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 1, False: 2]
24 // CHECK: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 0, False: 1]
25 bool g = MACRO3; // CHECK: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 1, False: 2]
26 // CHECK: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 0, False: 1]
27 return c && d && e && f && g;
28 // CHECK: | Branch ([[@LINE-1]]:10): [True: 0, False: 3]
29 // CHECK: | Branch ([[@LINE-2]]:15): [True: 0, False: 0]
30 // CHECK: | Branch ([[@LINE-3]]:20): [True: 0, False: 0]
31 // CHECK: | Branch ([[@LINE-4]]:25): [True: 0, False: 0]
32 // CHECK: | Branch ([[@LINE-5]]:30): [True: 0, False: 0]
36 bool func2(int a, int b) {
37 bool h = MACRO3 || COND4; // CHECK: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 1, False: 2]
38 // CHECK: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 0, False: 1]
39 // CHECK: | | | | | | | Branch ([[@LINE-34]]:15): [True: 1, False: 2]
40 // CHECK: | | | | | | | Branch ([[@LINE-34]]:15): [True: 0, False: 1]
41 // CHECK: | | | Branch ([[@LINE-33]]:15): [True: 1, False: 2]
42 return h;
45 extern "C" { extern void __llvm_profile_write_file(void); }
46 int main(int argc, char *argv[])
48 func(atoi(argv[1]), atoi(argv[2]));
49 func2(atoi(argv[1]), atoi(argv[2]));
50 __llvm_profile_write_file();
51 return 0;
54 // REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
55 // REPORT-NEXT: ---
56 // REPORT-NEXT: _Z4funcii 28 4 85.71% 18 0 100.00% 30 14 53.33%
57 // REPORT-NEXT: _Z5func2ii 13 1 92.31% 8 0 100.00% 10 2 80.00%
58 // REPORT-NEXT: main 1 0 100.00% 6 0 100.00% 0 0 0.00%
59 // REPORT-NEXT: ---
60 // REPORT-NEXT: TOTAL 42 5 88.10% 32 0 100.00% 40 16 60.00%