1 /*
2   bug-2349.c
3 */
4 
5 #include <testfwk.h>
6 
7 #pragma disable_warning 85
8 
subchar(void * pa,void * pb)9 long subchar(void *pa, void *pb)
10 {
11   return *((char *) pa) - *((char *) pb);
12 }
13 
subint(void * pa,void * pb)14 long subint(void *pa, void *pb)
15 {
16   return *((int *) pa) - *((int *) pb);
17 }
18 
sublong(void * pa,void * pb)19 long sublong(void *pa, void *pb)
20 {
21   return *((long *) pa) - *((long *) pb);
22 }
23 
addlong(void * pa,void * pb)24 long addlong(void *pa, void *pb)
25 {
26   return *((long *) pa) + *((long *) pb);
27 }
28 
29 #define NULL ((void *) 0)
30 
31 #if defined (__SDCC_MODEL_MEDIUM)
32 typedef long (*subfunc_t)(void *pa, void * __pdata pb);
33 #elif defined (__SDCC_MODEL_LARGE)
34 typedef long (*subfunc_t)(void *pa, void * __xdata pb);
35 #elif defined (__SDCC_MODEL_HUGE)
36 typedef long (*subfunc_t)(void *pa, void * __xdata pb);
37 #else
38 typedef long (*subfunc_t)(void *pa, void *pb);
39 #endif
40 
dosub(subfunc_t f)41 subfunc_t dosub(subfunc_t f)
42 {
43 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15)
44   if (f == subchar)
45     return subint;
46   else if (f == subint)
47     return sublong;
48   else if (f == sublong)
49     return subchar;
50   else if (f == NULL)
51     return addlong;
52   else
53     return NULL;
54 #endif
55 }
56 
testBug(void)57 void testBug(void)
58 {
59 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15)
60   ASSERT (dosub(subchar) == subint);
61   ASSERT (dosub(subint) == sublong);
62   ASSERT (dosub(sublong) == subchar);
63   ASSERT (dosub(addlong) == NULL);
64   ASSERT (dosub(NULL) == addlong);
65 #endif
66 }
67