1 // RUN: llvm-profdata merge %S/Inputs/branch-logical-mixed.proftext -o %t.profdata
2 // RUN: llvm-cov show --show-branches=count %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
3 // RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORT
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 
func(int a,int b)8 void func(int a, int b) {
9   bool b0 = a <= b;
10   bool b1 = a == b;
11   bool b2 = a >= b;
12   bool b3 = a < b;
13   bool b4 = a > b;
14   bool b5 = a != b;
15 
16   bool c = b0 &&           // CHECK: Branch ([[@LINE]]:12): [True: 3, False: 1]
17            b1 &&           // CHECK: Branch ([[@LINE]]:12): [True: 2, False: 1]
18            b2 &&           // CHECK: Branch ([[@LINE]]:12): [True: 2, False: 0]
19            b3 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 2]
20            b4 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
21            b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
22 
23   bool d = b0 ||           // CHECK: Branch ([[@LINE]]:12): [True: 3, False: 1]
24            b1 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 1]
25            b2 ||           // CHECK: Branch ([[@LINE]]:12): [True: 1, False: 0]
26            b3 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
27            b4 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
28            b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
29 
30   bool e = (b0  &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 1]
31             b5) ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
32            (b1  &&         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 1]
33             b4) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 2]
34            (b2  &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
35             b3) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
36            (b3  &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
37             b2) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
38            (b4  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
39             b1) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]
40            (b5  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
41             b0);           // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]
42 
43   bool f = (b0  ||         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 1]
44             b5) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 0]
45            (b1  ||         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 2]
46             b4) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 1]
47            (b2  ||         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
48             b3) &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
49            (b3  ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
50             b2) &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
51            (b4  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
52             b1) &&         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 0]
53            (b5  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
54             b0);           // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 0]
55 
56   if (c)                   // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 4]
57     printf("case0\n");
58   else
59     printf("case1\n");
60 
61   if (d)                   // CHECK: Branch ([[@LINE]]:7): [True: 4, False: 0]
62     printf("case2\n");
63   else
64     printf("case3\n");
65 
66   if (e)                   // CHECK: Branch ([[@LINE]]:7): [True: 1, False: 3]
67     printf("case4\n");
68   else
69     printf("case5\n");
70 
71   if (f)                   // CHECK: Branch ([[@LINE]]:7): [True: 3, False: 1]
72     printf("case6\n");
73   else
74     printf("case7\n");
75 }
76 
77 extern "C" { extern void __llvm_profile_write_file(void); }
main(int argc,char * argv[])78 int main(int argc, char *argv[])
79 {
80   func(atoi(argv[1]), atoi(argv[2]));
81   __llvm_profile_write_file();
82   return 0;
83 }
84 
85 // REPORT: Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
86 // REPORT-NEXT: ---
87 // REPORT-NEXT: _Z4funcii                        77       9  88.31%        68       3  95.59%        80      32  60.00%
88 // REPORT-NEXT: main                              1       0 100.00%         5       0 100.00%         0       0   0.00%
89 // REPORT-NEXT: ---
90 // REPORT-NEXT: TOTAL                            78       9  88.46%        73       3  95.89%        80      32  60.00%
91