| 1 |
/* { dg-options "-fcondition-coverage -ftest-coverage" } */ |
| 2 |
/* { dg-do run { target native } } */ |
| 3 |
|
| 4 |
#include <setjmp.h> |
| 5 |
jmp_buf buf; |
| 6 |
|
| 7 |
void noop () {} |
| 8 |
int identity (int x) { return x; } |
| 9 |
|
| 10 |
/* This function is a test to verify that the expression isolation does not |
| 11 |
break on a CFG with the right set of complex edges. The (_ && setjmp) |
| 12 |
created complex edges after the function calls and a circular pair of |
| 13 |
complex edges around the setjmp call. This triggered a bug when the search |
| 14 |
for right operands only would consider nodes dominated by the left-most |
| 15 |
term, as this would only be the case if the complex edges were removed. (_ |
| 16 |
&& setjmp) is undefined behavior, but it does happen in the wild. |
| 17 |
|
| 18 |
__builtin_setjmp did not trigger this, so we need setjmp from libc. */ |
| 19 |
void |
| 20 |
setjmp001 (int a, int b, int c) |
| 21 |
{ |
| 22 |
if (a) /* conditions(1/2) true(0) */ |
| 23 |
/* conditions(end) */ |
| 24 |
noop (); |
| 25 |
|
| 26 |
if (b) /* conditions(1/2) false(0) */ |
| 27 |
/* conditions(end) */ |
| 28 |
noop (); |
| 29 |
|
| 30 |
if (c && setjmp (buf)) /* conditions(1/4) true(0 1) false(1) */ |
| 31 |
/* conditions(end) */ |
| 32 |
noop (); |
| 33 |
} |
| 34 |
|
| 35 |
/* Adapted from freetype-2.13.0 gxvalid/gxvmod.c classic_kern_validate */ |
| 36 |
int |
| 37 |
setjmp002 (int a) |
| 38 |
{ |
| 39 |
int error = identity(a); |
| 40 |
|
| 41 |
if (error) /* conditions(1/2) true(0) */ |
| 42 |
/* conditions(end) */ |
| 43 |
goto Exit; |
| 44 |
|
| 45 |
if (a+1) /* conditions(1/2) false(0) */ |
| 46 |
/* conditions(end) */ |
| 47 |
{ |
| 48 |
noop (); |
| 49 |
if (setjmp (buf)) /* conditions(1/2) true(0) */ |
| 50 |
/* conditions(end) */ |
| 51 |
noop (); |
| 52 |
|
| 53 |
if (error) /* conditions(1/2) true(0) */ |
| 54 |
/* conditions(end) */ |
| 55 |
noop (); |
| 56 |
} |
| 57 |
|
| 58 |
error--; |
| 59 |
|
| 60 |
Exit: |
| 61 |
return error; |
| 62 |
} |
| 63 |
|
| 64 |
int |
| 65 |
setjmp003 (int a) |
| 66 |
{ |
| 67 |
/* || setjmp is undefined behavior, so the result here does not have to |
| 68 |
make sense. It would be nice if the result is not something like 35/4 |
| 69 |
conditions covered. */ |
| 70 |
if (a || setjmp (buf)) /* conditions(suppress) */ |
| 71 |
/* conditions(end) */ |
| 72 |
a += 12; |
| 73 |
|
| 74 |
return a; |
| 75 |
} |
| 76 |
|
| 77 |
jmp_buf dest; |
| 78 |
|
| 79 |
int |
| 80 |
setdest () |
| 81 |
{ |
| 82 |
if (setjmp (dest)) /* conditions(2/2) */ |
| 83 |
return 1; |
| 84 |
return 2; |
| 85 |
} |
| 86 |
|
| 87 |
void |
| 88 |
jump () |
| 89 |
{ |
| 90 |
/* Protect the longjmp so it will only be done once. The whole purpose of |
| 91 |
this function is to help test conditions and instrumentation around |
| 92 |
setjmp and its complex edges, as both branches should count towards |
| 93 |
coverage, even when one is taken through longjmp. If the jump is not |
| 94 |
guarded it can cause an infinite loop as setdest returns to a point in |
| 95 |
main before jump (), leading to an infinite loop. See PR |
| 96 |
gcov-profile/114720. */ |
| 97 |
static int called_once = 0; |
| 98 |
if (!called_once) /* conditions(suppress) */ |
| 99 |
{ |
| 100 |
called_once = 1; |
| 101 |
longjmp (dest, 1); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
int |
| 106 |
main () |
| 107 |
{ |
| 108 |
setjmp001 (0, 1, 0); |
| 109 |
setjmp002 (0); |
| 110 |
setjmp003 (0); |
| 111 |
setdest (); |
| 112 |
jump (); |
| 113 |
} |
| 114 |
|
| 115 |
/* { dg-final { run-gcov conditions { --conditions gcov-22.c } } } */ |