summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-pure-1.c
blob: 759cccc7fa6d2186ce9582f68ea2ee11ca570c4c (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
   restrict-1.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> 2002-05-27.  */

extern int i;

extern int func0 (int);
extern int func1 (int);

/* GCC should automatically detect attributes for these functions.
   At -O3 They'll be inlined, but that's ok.  */
static int func2 (int a) { return i + a; } /* pure */
static int func3 (int a) { return a * 3; } /* const */
static int func4 (int a) { return func0(a) + a; } /* pure */
static int func5 (int a) { return a + func1(a); } /* const */
static int func6 (int a) { return func2(a) + a; } /* pure */
static int func7 (int a) { return a + func3(a); } /* const */

void
testTortureExecute (void)
{
#ifndef __SDCC_pdk14 // Lack of memory
  int i[10], r;

  i[0] = 0;
  r = func0(0);
  if (i[0])
    ASSERT (0);

  i[1] = 0;
  r = func1(0);
  if (i[1])
    ASSERT (0);

  i[2] = 0;
  r = func2(0);
  if (i[2])
    ASSERT (0);

  i[3] = 0;
  r = func3(0);
  if (i[3])
    ASSERT (0);

  i[4] = 0;
  r = func4(0);
  if (i[4])
    ASSERT (0);

  i[5] = 0;
  r = func5(0);
  if (i[5])
    ASSERT (0);

  i[6] = 0;
  r = func6(0);
  if (i[6])
    ASSERT (0);

  i[7] = 0;
  r = func7(0);
  if (i[7])
    ASSERT (0);

  return;
#endif
}

int func0 (int a) { return a - i; } /* pure */
int func1 (int a) { return a - a; } /* const */

int i = 2;