[2/2] gcov: test line count for label in then/else block

Message ID 20221011124303.99673-2-jorgen.kvalsvik@woven-planet.global
State Accepted, archived
Headers
Series [1/2] gcov: test switch/break line counts |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jørgen Kvalsvik Oct. 11, 2022, 12:43 p.m. UTC
  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:
---
 gcc/testsuite/gcc.misc-tests/gcov-4.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
  

Comments

Richard Biener Oct. 13, 2022, 11:40 a.m. UTC | #1
On Tue, Oct 11, 2022 at 2:43 PM Jørgen Kvalsvik
<jorgen.kvalsvik@woven-planet.global> wrote:
>
> 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.

OK.

> gcc/testsuite/ChangeLog:
>
>         * gcc.misc-tests/gcov-4.c:
> ---
>  gcc/testsuite/gcc.misc-tests/gcov-4.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> index 498d299b66b..da7929ef7fc 100644
> --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
> +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> @@ -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)
> --
> 2.34.0
>
  

Patch

diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
index 498d299b66b..da7929ef7fc 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
@@ -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)