aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/cet-sjlj-3.c
blob: 25117cc0c9fdff9fa09308c4a9eceb6cf52bea08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* { dg-do compile } */
/* { dg-options "-O -fcf-protection" } */
/* { dg-final { scan-assembler-times "endbr32" 4 { target ia32 } } } */
/* { dg-final { scan-assembler-times "endbr64" 4 { target { ! ia32 } } } } */
/* { dg-final { scan-assembler-times "call	_?setjmp" 1 } } */
/* { dg-final { scan-assembler-times "call	longjmp" 1 } } */

#include <stdio.h>
#include <setjmp.h>

jmp_buf buf;
int bar (int);

int
foo (int i)
{
  int j = i * 11;

  if (!setjmp (buf))
    {
      j += 33;
      printf ("After setjmp: j = %d\n", j);
      bar (j);
    }

  return j + i;
}

int
bar (int i)
{
int j = i;

  j -= 111;
  printf ("In longjmp: j = %d\n", j);
  longjmp (buf, 1);

  return j;
}

int
main ()
{
  foo (10);
  return 0;
}