]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Guard longjmp in test to not inf loop [PR114720]
authorJørgen Kvalsvik <j@lambda.is>
Mon, 15 Apr 2024 12:14:26 +0000 (14:14 +0200)
committerJørgen Kvalsvik <j@lambda.is>
Mon, 15 Apr 2024 13:34:42 +0000 (15:34 +0200)
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

index 641791a722340fbc0059260e429e557e63ceb6d6..7ca78467ca318ad89d342c4cfa39deeeec0874ce 100644 (file)
@@ -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