public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Guard longjmp in test to not inf loop [PR114720]
@ 2024-04-15 12:34 Jørgen Kvalsvik
  2024-04-15 12:48 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jørgen Kvalsvik @ 2024-04-15 12:34 UTC (permalink / raw)
  To: gcc-patches; +Cc: hubicka, ro, Jørgen Kvalsvik

Guard the longjmp to not infinitely loop. The longjmp (jump) function is
called unconditionally to make test flow simpler, but the jump
destination would return to a point in main that would call longjmp
again. The longjmp is really there to exercise the then-branch of
setjmp, to verify coverage is accurately counted in the presence of
complex edges.

	PR gcov-profile/114720

gcc/testsuite/ChangeLog:

	* gcc.misc-tests/gcov-22.c: Guard longjmp to not loop.
---
 gcc/testsuite/gcc.misc-tests/gcov-22.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.misc-tests/gcov-22.c b/gcc/testsuite/gcc.misc-tests/gcov-22.c
index 641791a7223..7ca78467ca3 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-22.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-22.c
@@ -87,7 +87,19 @@ setdest ()
 void
 jump ()
 {
-    longjmp (dest, 1);
+    /* Protect the longjmp so it will only be done once.  The whole purpose of
+       this function is to help test conditions and instrumentation around
+       setjmp and its complex edges, as both branches should count towards
+       coverage, even when one is taken through longjmp.  If the jump is not
+       guarded it can cause an infinite loop as setdest returns to a point in
+       main before jump (), leading to an infinite loop.  See PR
+       gcov-profile/114720.  */
+    static int called_once = 0;
+    if (!called_once) /* conditions(suppress) */
+    {
+	called_once = 1;
+	longjmp (dest, 1);
+    }
 }
 
 int
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Guard longjmp in test to not inf loop [PR114720]
  2024-04-15 12:34 [PATCH] Guard longjmp in test to not inf loop [PR114720] Jørgen Kvalsvik
@ 2024-04-15 12:48 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-04-15 12:48 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: gcc-patches, hubicka, ro

On Mon, Apr 15, 2024 at 2:35 PM Jørgen Kvalsvik <j@lambda.is> wrote:
>
> Guard the longjmp to not infinitely loop. The longjmp (jump) function is
> called unconditionally to make test flow simpler, but the jump
> destination would return to a point in main that would call longjmp
> again. The longjmp is really there to exercise the then-branch of
> setjmp, to verify coverage is accurately counted in the presence of
> complex edges.

OK

>         PR gcov-profile/114720
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.misc-tests/gcov-22.c: Guard longjmp to not loop.
> ---
>  gcc/testsuite/gcc.misc-tests/gcov-22.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-22.c b/gcc/testsuite/gcc.misc-tests/gcov-22.c
> index 641791a7223..7ca78467ca3 100644
> --- a/gcc/testsuite/gcc.misc-tests/gcov-22.c
> +++ b/gcc/testsuite/gcc.misc-tests/gcov-22.c
> @@ -87,7 +87,19 @@ setdest ()
>  void
>  jump ()
>  {
> -    longjmp (dest, 1);
> +    /* Protect the longjmp so it will only be done once.  The whole purpose of
> +       this function is to help test conditions and instrumentation around
> +       setjmp and its complex edges, as both branches should count towards
> +       coverage, even when one is taken through longjmp.  If the jump is not
> +       guarded it can cause an infinite loop as setdest returns to a point in
> +       main before jump (), leading to an infinite loop.  See PR
> +       gcov-profile/114720.  */
> +    static int called_once = 0;
> +    if (!called_once) /* conditions(suppress) */
> +    {
> +       called_once = 1;
> +       longjmp (dest, 1);
> +    }
>  }
>
>  int
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-15 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 12:34 [PATCH] Guard longjmp in test to not inf loop [PR114720] Jørgen Kvalsvik
2024-04-15 12:48 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).