Debian Codegraph @

gcc/testsuite/c-c++-common/hwasan/setjmp-longjmp-0.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target hwaddress_exec } */
3
4 #include <setjmp.h>
5 #include <stdio.h>
6
7 /*
8 Testing longjmp/setjmp should test.
9
10 0) Nothing special happens with the jmp_buf.
11 1) Accesses to scopes jmp'd over are caught.
12 */
13 int __attribute__ ((noinline))
14 uses_longjmp (int **other_array, int num, jmp_buf env)
15 {
16 int internal_array[100] = {0};
17 *other_array = &internal_array[0];
18 if (num % 2)
19 longjmp (env, num);
20 else
21 return num % 8;
22 }
23
24 int __attribute__ ((noinline))
25 uses_setjmp (int num)
26 {
27 int big_array[100];
28 int *other_array = NULL;
29 sigjmp_buf cur_env;
30 int temp = 0;
31 if ((temp = sigsetjmp (cur_env, 1)) != 0)
32 {
33 if (other_array != NULL)
34 printf ("Value pointed to in other_array[0]: %d\n",
35 other_array[0]);
36
37 printf ("Longjmp returned %d.\n", temp);
38 return 10;
39 }
40 else
41 {
42 return uses_longjmp (&other_array, num, cur_env);
43 }
44 }
45
46 #ifndef ARG
47 #define ARG 0
48 #endif
49 int __attribute__ ((noinline))
50 main ()
51 {
52 uses_setjmp (ARG);
53 return 0;
54 }