summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/torture/pr48542.c
blob: e3e49489f7dcac1d83e736f123727e898bcfdf7c (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
47
48
49
50
51
52
53
54
55
56
57
/* { dg-do run } */
/* The return-address was clobbered.  */
#include <stdlib.h>
#include <setjmp.h>

jmp_buf env;
extern void sub(void);
extern void sub3(void);
int called;
__attribute__ ((__noinline__))
int sjtest()
{
  int i;
  if (setjmp(env))
    return 99;

  for (i = 0; i < 10; i++)
    sub();

  longjmp(env, 1);
}

__attribute__ ((__noinline__))
void sub(void)
{
  called++;
}

int called3;
__attribute__ ((__noinline__))
int sjtest3()
{
  int i;
  if (setjmp(env))
    return 42;

  for (i = 0; i < 10; i++)
    sub3();
  return 0;
}

__attribute__ ((__noinline__))
void sub3(void)
{
  called3++;
  if (called3 == 10)
    longjmp (env, 1);
}

int main(void)
{
  if (sjtest() != 99 || called != 10)
    abort();
  if (sjtest3() != 42 || called3 != 10)
    abort();
  exit (0);
}