[2/2] gcov: test line count for label in then/else block
Checks
Commit Message
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
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
>
@@ -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)