xref: /llvm-project/clang/test/Profile/branch-profdup.cpp (revision 16f3401eae4310c95163269c41d9b45261f0c7c3)
19f2967bcSAlan Phipps // Test to ensure RHS condition of logical operators isn't evaluated more than
29f2967bcSAlan Phipps // one time when instrumenting RHS counter blocks for branch coverage.
39f2967bcSAlan Phipps 
4*16f3401eSAlan Phipps // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -main-file-name branch-profdup.cpp %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap %s
59f2967bcSAlan Phipps 
69f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test1b
79f2967bcSAlan Phipps // CHECK-COUNT-1: = call {{.*}}@_Z5fval1v()
89f2967bcSAlan Phipps // CHECK-NOT: = call {{.*}}@_Z5fval1v()
99f2967bcSAlan Phipps extern bool fval1();
test1(bool a)109f2967bcSAlan Phipps bool test1(bool a) {
119f2967bcSAlan Phipps   return (a && fval1());
129f2967bcSAlan Phipps }
139f2967bcSAlan Phipps 
149f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test2b
159f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval2v()
169f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval2v()
179f2967bcSAlan Phipps extern bool fval2();
test2(bool a)189f2967bcSAlan Phipps bool test2(bool a) {
199f2967bcSAlan Phipps   return (a || fval2());
209f2967bcSAlan Phipps }
219f2967bcSAlan Phipps 
229f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test3v
239f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval3v()
249f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval3v()
259f2967bcSAlan Phipps extern bool fval3();
test3()269f2967bcSAlan Phipps bool test3() {
279f2967bcSAlan Phipps   return (1 && fval3());
289f2967bcSAlan Phipps }
299f2967bcSAlan Phipps 
309f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test4v
319f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval4v()
329f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval4v()
339f2967bcSAlan Phipps extern bool fval4();
test4()349f2967bcSAlan Phipps bool test4() {
359f2967bcSAlan Phipps   return (0 || fval4());
369f2967bcSAlan Phipps }
379f2967bcSAlan Phipps 
389f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test5b
399f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval5v()
409f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval5v()
419f2967bcSAlan Phipps extern bool fval5();
test5(bool a)429f2967bcSAlan Phipps bool test5(bool a) {
439f2967bcSAlan Phipps   if (a && fval5())
449f2967bcSAlan Phipps     return true;
459f2967bcSAlan Phipps   return false;
469f2967bcSAlan Phipps }
479f2967bcSAlan Phipps 
489f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test6b
499f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval6v()
509f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval6v()
519f2967bcSAlan Phipps extern bool fval6();
test6(bool a)529f2967bcSAlan Phipps bool test6(bool a) {
539f2967bcSAlan Phipps   if (a || fval6())
549f2967bcSAlan Phipps     return true;
559f2967bcSAlan Phipps   return false;
569f2967bcSAlan Phipps }
579f2967bcSAlan Phipps 
589f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test7v
599f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval7v()
609f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval7v()
619f2967bcSAlan Phipps extern bool fval7();
test7()629f2967bcSAlan Phipps bool test7() {
639f2967bcSAlan Phipps   if (1 && fval7())
649f2967bcSAlan Phipps     return true;
659f2967bcSAlan Phipps   return false;
669f2967bcSAlan Phipps }
679f2967bcSAlan Phipps 
689f2967bcSAlan Phipps // CHECK-LABEL: define {{.*}}@_Z5test8v
699f2967bcSAlan Phipps // CHECK-COUNT-1: call {{.*}}_Z5fval8v()
709f2967bcSAlan Phipps // CHECK-NOT: call {{.*}}_Z5fval8v()
719f2967bcSAlan Phipps extern bool fval8();
test8()729f2967bcSAlan Phipps bool test8() {
739f2967bcSAlan Phipps   if (0 || fval8())
749f2967bcSAlan Phipps     return true;
759f2967bcSAlan Phipps   return false;
769f2967bcSAlan Phipps }
77