summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/nested-func-8.c
blob: ccec27d08fbdcfd20cc6d7fa39a8e1a962b1359c (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 } */
/* { dg-options "-O -fno-inline" } */

extern void abort (void);

/* Return 0 and clobber the static chain.  */

int
zero (int n)
{
  int
  nested (int m)
  {
    return m - n;
  }

  return nested (n);
}

/* Return the triple of ARG in a convoluted manner.  */

int
triple (int arg)
{
  int
  read_arg (void)
  {
    return arg;
  }

  int
  parent (int nested_arg)
  {
    int
    child1 (void)
    {
      return parent (zero (5));
    }

    int
    child2 (void)
    {
      return nested_arg + read_arg ();
    }

    return (nested_arg == 0 ? 0 : child1 ()) + child2 ();
  }

  return parent (arg);
}

int main(void)
{
  if (triple (13) != 3 * 13)
    abort ();
  return 0;
}