19f2967bcSAlan Phipps // Test to ensure right number of counters are allocated and used for nested
29f2967bcSAlan Phipps // logical operators on branch conditions for branch coverage.
39f2967bcSAlan Phipps
416f3401eSAlan Phipps // 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*8b2bdfbcSAlan Phipps // 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
69f2967bcSAlan Phipps
79f2967bcSAlan Phipps
89f2967bcSAlan Phipps // CHECK-LABEL: _Z5func1ii:
func1(int a,int b)99f2967bcSAlan Phipps bool func1(int a, int b) {
109f2967bcSAlan Phipps bool b0 = a <= b;
119f2967bcSAlan Phipps bool b1 = a == b;
129f2967bcSAlan Phipps bool b2 = a >= b;
139f2967bcSAlan Phipps
149f2967bcSAlan Phipps // This should allocate a RHS branch counter on b2 (counter #3).
159f2967bcSAlan Phipps bool c = b0 && (b1 || b2);
169f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-1]]:12 -> [[@LINE-1]]:14 = #1, (#0 - #1)
179f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = (#1 - #2), #2
189f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-3]]:25 -> [[@LINE-3]]:27 = (#2 - #3), #3
199f2967bcSAlan Phipps
209f2967bcSAlan Phipps return c;
219f2967bcSAlan Phipps }
229f2967bcSAlan Phipps
239f2967bcSAlan Phipps // CHECK-LABEL: _Z5func2ii:
func2(int a,int b)249f2967bcSAlan Phipps bool func2(int a, int b) {
259f2967bcSAlan Phipps bool b0 = a <= b;
269f2967bcSAlan Phipps bool b1 = a == b;
279f2967bcSAlan Phipps bool b2 = a >= b;
289f2967bcSAlan Phipps
299f2967bcSAlan Phipps // This should allocate a RHS branch counter on b1 and b2 (counters #2, #4)
309f2967bcSAlan Phipps // This could possibly be further optimized through counter reuse (future).
319f2967bcSAlan Phipps bool c = (b0 && b1) || b2;
329f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-1]]:13 -> [[@LINE-1]]:15 = #3, (#0 - #3)
339f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = #4, (#3 - #4)
349f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-3]]:26 -> [[@LINE-3]]:28 = (#1 - #2), #2
359f2967bcSAlan Phipps
369f2967bcSAlan Phipps return c;
379f2967bcSAlan Phipps }
389f2967bcSAlan Phipps
399f2967bcSAlan Phipps // CHECK-LABEL: _Z5func3ii:
func3(int a,int b)409f2967bcSAlan Phipps bool func3(int a, int b) {
419f2967bcSAlan Phipps bool b0 = a <= b;
429f2967bcSAlan Phipps bool b1 = a == b;
439f2967bcSAlan Phipps bool b2 = a >= b;
449f2967bcSAlan Phipps bool b3 = a < b;
459f2967bcSAlan Phipps
469f2967bcSAlan Phipps // This should allocate a RHS branch counter on b1 and b3 (counters #3, #5)
479f2967bcSAlan Phipps // This could possibly be further optimized through counter reuse (future).
489f2967bcSAlan Phipps bool c = (b0 || b1) && (b2 || b3);
499f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-1]]:13 -> [[@LINE-1]]:15 = (#0 - #2), #2
509f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-2]]:19 -> [[@LINE-2]]:21 = (#2 - #3), #3
519f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-3]]:27 -> [[@LINE-3]]:29 = (#1 - #4), #4
529f2967bcSAlan Phipps // CHECK: Branch,File 0, [[@LINE-4]]:33 -> [[@LINE-4]]:35 = (#4 - #5), #5
539f2967bcSAlan Phipps
549f2967bcSAlan Phipps return c;
559f2967bcSAlan Phipps }
56