diff mbox series

[11/22] Add test case showing cross-decision fusing

Message ID 20231004123921.634024-12-j@lambda.is
State New
Headers show
Series [01/22] Add condition coverage profiling | expand

Commit Message

Jørgen Kvalsvik Oct. 4, 2023, 12:39 p.m. UTC
Some expressions create CFGs isomorphic to those with multi-term
expressions, e.g. if (a) if (b) {} is equivalent to if (a && b) {}, and
there is no real recovery for this. The test is added to 1. document the
behaviour and 2. detect if the cfg generation changes in a way that
(correctly) splits the ifs.

Note that some arithmetic is performed between the else-if and the
following if. This is not sufficient to create a new basic block, and
all sorts of arithmetic and side effect is possible between terms in an
arbitrary boolean expression anyway, for example if (a++ && --b).
---
 gcc/testsuite/gcc.misc-tests/gcov-19.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.misc-tests/gcov-19.c b/gcc/testsuite/gcc.misc-tests/gcov-19.c
index 662f4ca2864..5b5c1c275b0 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-19.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-19.c
@@ -146,6 +146,26 @@  mcdc004e (int a, int b, int c)
     }
 }
 
+/* else-if is not immune to the else-less fuse.  This test is also put in as a
+ * detection mechanism - sif this should register as 3 individual decisions
+ * then the test should be updated and fixed to reflect it.  */
+int
+mcdc004f (int a, int b, int c)
+{
+    if (a)  /* conditions(1/2) false(0) */
+	    /* conditions(end) */
+    {
+	x = 1;
+    }
+    else if (b) /* conditions(0/4) true(0 1) false(0 1) */
+		/* conditions(end) */
+    {
+	x = 2;
+	if (c)
+	    x = 3;
+    }
+}
+
 /* mixing && and || works */
 void
 mcdc005a (int a, int b, int c)
@@ -1137,6 +1157,8 @@  int main ()
     mcdc004e (0, 0, 0);
     mcdc004e (1, 1, 1);
 
+    mcdc004f (1, 1, 1);
+
     mcdc005a (1, 0, 1);
 
     mcdc005b (1, 1, 0, 0);