summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2455.c
blob: d5011a10c2a550222ac9f610bb193ea3c01b7250 (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
/*
   bug-2455.c
*/

#include <testfwk.h>

#if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // pdk needs function pointer to be reentrant even for a single argument
typedef int (*funcType) (int);

int foo0 (int a)
{
  return a + 2;
}

int foo1 (int a)
{
  return a - 6;
}

int foo2 (int a)
{
  return a * 2;
}

struct
{
  funcType fpa[2];
  funcType fpb;
} testS = {{foo0, foo1}, foo2};
#endif

void testBug (void)
{
#if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15)
  ASSERT (testS.fpa[0] (5) == 7);
  ASSERT (testS.fpa[1] (9) == 3);
  ASSERT (testS.fpb (5) == 10);

  testS.fpa[0] = foo1;
  testS.fpa[1] = foo2;
  testS.fpb = foo0;

  ASSERT (testS.fpa[0] (5) == -1);
  ASSERT (testS.fpa[1] (9) == 18);
  ASSERT (testS.fpb (5) == 7);

  testS.fpb = testS.fpa[0];
  testS.fpa[0] = testS.fpa[1];
  testS.fpa[1] = foo0;

  ASSERT (testS.fpa[0] (5) == 10);
  ASSERT (testS.fpa[1] (9) == 11);
  ASSERT (testS.fpb (5) == -1);
#endif
}