Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-716242.c
blob3764a50aabf58031f96f853cc6e16dc594f1d839
1 /* bug-716242.c
3 syntax tests about function pointers at compile time
5 This also tests an implementation extension that allows the casting of void * to function pointers,
6 which is not available for the stm8 large memory model.
7 */
8 #include <testfwk.h>
10 #pragma disable_warning 244
12 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // pdk needs functions called via pointer to be reentrant even for a single argument
13 const void *p;
14 int ret;
16 int
17 mul2 (int i)
19 return 2 * i;
22 void
23 g (int (*h) (int))
25 ret = h (2);
28 void
29 f1 ()
31 #if !((defined __SDCC_stm8) && defined (__SDCC_MODEL_LARGE))
32 #if defined(__SDCC_ds390)
33 p = (void __code *) mul2;
34 #else
35 p = (void *) mul2;
36 #endif
37 g ((int (*) (int)) p);
38 #endif
41 /****************************/
43 void g (int (*h) (int));
45 void
46 f2 ()
48 int (*fp) (int) = p;
50 g (fp);
53 /****************************/
55 void g (int (*h) (int));
57 void
58 f3 ()
60 int (*fp) (int) = (int (*) (int)) p;
62 g (fp);
65 /****************************/
67 void
68 f4 ()
70 ((void (__code *) (void)) p) ();
73 /****************************/
75 void
76 f5 ()
78 int (*fp) (int) = mul2;
80 fp (1);
83 /****************************/
85 void
86 f6 ()
88 ((void (__code *) (void)) 0) ();
91 /****************************/
92 #endif
94 static void
95 testFuncPtr (void)
97 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
98 #if !((defined __SDCC_stm8) && defined (__SDCC_MODEL_LARGE)) // STM8 large model has sizeof(void *) != size of function pointers.
99 f1 ();
100 ASSERT (ret == 4);
101 #endif
102 #endif