xref: /llvm-project/clang/test/CoverageMapping/branch-mincounters.cpp (revision 8b2bdfbca7c1db272e4e703445f5626b4bc4b9d3)
1 // Test to ensure right number of counters are allocated and used for nested
2 // logical operators on branch conditions for branch coverage.
3 
4 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-logical-mixed.cpp %s | FileCheck %s
5 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -fcoverage-mcdc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-logical-mixed.cpp %s | FileCheck %s
6 
7 
8 // CHECK-LABEL: _Z5func1ii:
func1(int a,int b)9 bool func1(int a, int b) {
10   bool b0 = a <= b;
11   bool b1 = a == b;
12   bool b2 = a >= b;
13 
14   // This should allocate a RHS branch counter on b2 (counter #3).
15   bool c = b0 && (b1 || b2);
16   // CHECK: Branch,File 0, [[@LINE-1]]:12 -> [[@LINE-1]]:14 = #1, (#0 - #1)
17   // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = (#1 - #2), #2
18   // CHECK: Branch,File 0, [[@LINE-3]]:25 -> [[@LINE-3]]:27 = (#2 - #3), #3
19 
20   return c;
21 }
22 
23 // CHECK-LABEL: _Z5func2ii:
func2(int a,int b)24 bool func2(int a, int b) {
25   bool b0 = a <= b;
26   bool b1 = a == b;
27   bool b2 = a >= b;
28 
29   // This should allocate a RHS branch counter on b1 and b2 (counters #2, #4)
30   // This could possibly be further optimized through counter reuse (future).
31   bool c = (b0 && b1) || b2;
32   // CHECK: Branch,File 0, [[@LINE-1]]:13 -> [[@LINE-1]]:15 = #3, (#0 - #3)
33   // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = #4, (#3 - #4)
34   // CHECK: Branch,File 0, [[@LINE-3]]:26 -> [[@LINE-3]]:28 = (#1 - #2), #2
35 
36   return c;
37 }
38 
39 // CHECK-LABEL: _Z5func3ii:
func3(int a,int b)40 bool func3(int a, int b) {
41   bool b0 = a <= b;
42   bool b1 = a == b;
43   bool b2 = a >= b;
44   bool b3 = a < b;
45 
46   // This should allocate a RHS branch counter on b1 and b3 (counters #3, #5)
47   // This could possibly be further optimized through counter reuse (future).
48   bool c = (b0 || b1) && (b2 || b3);
49   // CHECK: Branch,File 0, [[@LINE-1]]:13 -> [[@LINE-1]]:15 = (#0 - #2), #2
50   // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = (#2 - #3), #3
51   // CHECK: Branch,File 0, [[@LINE-3]]:27 -> [[@LINE-3]]:29 = (#1 - #4), #4
52   // CHECK: Branch,File 0, [[@LINE-4]]:33 -> [[@LINE-4]]:35 = (#4 - #5), #5
53 
54   return c;
55 }
56