File: branch-logical-mixed.cpp

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (90 lines) | stat: -rw-r--r-- 4,722 bytes parent folder | download | duplicates (15)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// RUN: llvm-profdata merge %S/Inputs/branch-logical-mixed.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=count %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
// 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

#include <stdio.h>
#include <stdlib.h>

void func(int a, int b) {
  bool b0 = a <= b;
  bool b1 = a == b;
  bool b2 = a >= b;
  bool b3 = a < b;
  bool b4 = a > b;
  bool b5 = a != b;

  bool c = b0 &&           // CHECK: Branch ([[@LINE]]:12): [True: 3, False: 1]
           b1 &&           // CHECK: Branch ([[@LINE]]:12): [True: 2, False: 1]
           b2 &&           // CHECK: Branch ([[@LINE]]:12): [True: 2, False: 0]
           b3 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 2]
           b4 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
           b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]

  bool d = b0 ||           // CHECK: Branch ([[@LINE]]:12): [True: 3, False: 1]
           b1 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 1]
           b2 ||           // CHECK: Branch ([[@LINE]]:12): [True: 1, False: 0]
           b3 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
           b4 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
           b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]

  bool e = (b0  &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 1]
            b5) ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
           (b1  &&         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 1]
            b4) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 2]
           (b2  &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
            b3) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
           (b3  &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
            b2) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
           (b4  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
            b1) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]
           (b5  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
            b0);           // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]

  bool f = (b0  ||         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 1]
            b5) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 0]
           (b1  ||         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 2]
            b4) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 1]
           (b2  ||         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
            b3) &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
           (b3  ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 3]
            b2) &&         // CHECK: Branch ([[@LINE]]:13): [True: 3, False: 0]
           (b4  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
            b1) &&         // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 0]
           (b5  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 2]
            b0);           // CHECK: Branch ([[@LINE]]:13): [True: 2, False: 0]

  if (c)                   // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 4]
    printf("case0\n");
  else
    printf("case1\n");

  if (d)                   // CHECK: Branch ([[@LINE]]:7): [True: 4, False: 0]
    printf("case2\n");
  else
    printf("case3\n");

  if (e)                   // CHECK: Branch ([[@LINE]]:7): [True: 1, False: 3]
    printf("case4\n");
  else
    printf("case5\n");

  if (f)                   // CHECK: Branch ([[@LINE]]:7): [True: 3, False: 1]
    printf("case6\n");
  else
    printf("case7\n");
}

extern "C" { extern void __llvm_profile_write_file(void); }
int main(int argc, char *argv[])
{
  func(atoi(argv[1]), atoi(argv[2]));
  __llvm_profile_write_file();
  return 0;
}

// REPORT: Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
// REPORT-NEXT: ---
// REPORT-NEXT: _Z4funcii                        77       9  88.31%        68       3  95.59%        80      32  60.00%
// REPORT-NEXT: main                              1       0 100.00%         5       0 100.00%         0       0   0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL                            78       9  88.46%        73       3  95.89%        80      32  60.00%