]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov: test line count for label in then/else block
authorJørgen Kvalsvik <jorgen.kvalsvik@woven-planet.global>
Fri, 7 Oct 2022 11:29:20 +0000 (13:29 +0200)
committerJørgen Kvalsvik <jorgen.kvalsvik@woven-planet.global>
Fri, 14 Oct 2022 08:46:28 +0000 (10:46 +0200)
Add a test to catch regression in line counts for labels on top of
then/else blocks. Only the 'goto <label>' should contribute to the line
counter for the label, not the if.

gcc/testsuite/ChangeLog:

* gcc.misc-tests/gcov-4.c: New testcase.

gcc/testsuite/gcc.misc-tests/gcov-4.c

index 498d299b66b0853d1dabdf09056537a8879791a4..da7929ef7fcd30f00d0c68a451e95c3d8ee4a587 100644 (file)
@@ -110,6 +110,29 @@ lab2:
   return 8;                            /* count(1) */
 }
 
+int
+test_goto3 (int i, int j)
+{
+    if (j) goto else_;         /* count(1) */
+
+top:
+    if (i)                     /* count(1) */
+      {
+       i = do_something (i);
+      }
+    else
+      {
+else_:                         /* count(1) */
+       j = do_something (j);   /* count(2) */
+       if (j)                  /* count(2) */
+         {
+           j = 0;              /* count(1) */
+           goto top;           /* count(1) */
+         }
+      }
+    return 16;
+}
+
 void
 call_goto ()
 {
@@ -117,6 +140,7 @@ call_goto ()
   goto_val += test_goto1 (1);
   goto_val += test_goto2 (3);
   goto_val += test_goto2 (30);
+  goto_val += test_goto3 (0, 1);
 }
 
 /* Check nested if-then-else statements. */
@@ -260,7 +284,7 @@ main()
   call_unref ();
   if ((for_val1 != 12)
       || (for_val2 != 87)
-      || (goto_val != 15)
+      || (goto_val != 31)
       || (ifelse_val1 != 31)
       || (ifelse_val2 != 23)
       || (ifelse_val3 != 246)