Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / reentrant.c.in
blob9637eadddb6e73d9acbb06c762a3ffbb1cefc3fd
1 /** reentrant.c
3 type: unsigned char, unsigned int, signed int, unsigned long, signed long, unsigned long long, signed long long, float
4 */
6 #include <testfwk.h>
7 #include <stdlib.h>
9 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
10 #if !defined( __SDCC_ds390) // Bug 3307
12 {type} sum({type} a) __reentrant
14 if(a>1) return a+sum(a-1);
15 return 1;
18 {type} fact({type} a) __reentrant
20 if(a>1) return a*fact(a-1);
21 return 1;
24 {type} div2n({type} a, int n) __reentrant
26 if(n>0) return div2n(a/2,n-1);
27 return a;
30 {type} fib({type} a) __reentrant
32 if(a>1) return fib(a-1)+fib(a-2);
33 return a;
36 #endif
37 #endif
39 void
40 testReent(void)
42 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
43 #if !defined( __SDCC_ds390) // Bug 3307
44 ASSERT(sum(9) == 45);
45 ASSERT(fact(5) == 120);
46 ASSERT(div2n(128, 7) == 1);
47 ASSERT(fib(7) == 13);
48 #endif
49 #endif