Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-2964.c
blobd56f4ac17571475c6d5ec455810418f2e363dbb5
1 /*
2 bug-2964.c
4 A bug in stm8 code generation for left shift triggered by stack allocation allocating
5 result and right operands of a left shift to the stack, to overlapping locations.
6 */
8 #include <testfwk.h>
10 unsigned long long j;
12 unsigned char c;
13 unsigned long long i;
15 // Just some function that won't be inlined, so calls to it will result in spilling of local variables.
16 void g(void)
18 j += 42 + i;
21 unsigned long long f1(void)
23 unsigned char d = c + 1;
24 j |= 7;
25 unsigned long long l1 = i + 1;
26 g();
27 g();
28 unsigned long long l2 = l1 << d;
30 return l2;
33 #ifndef __SDCC_pdk14 // Lack of RAM
34 unsigned long long f2(void)
36 unsigned char d = c + 1;
37 j |= 7;
38 unsigned long long l1 = i + 1;
39 g();
40 g();
41 g();
42 g();
43 unsigned long long l2 = l1 << d;
45 return l2;
48 unsigned long long f3(void)
50 unsigned char d = c + 1;
51 g();
52 g();
53 unsigned long long l2 = i << d;
55 return l2;
57 #endif
59 void testBug(void)
61 j = 1;
63 c = 0;
64 i = 1;
65 ASSERT(f1() == 4);
67 #ifndef __SDCC_pdk14 // Lack of RAM
68 c = 1;
69 i = 3;
70 ASSERT(f2() == 16);
72 c = 1;
73 i = 8;
74 ASSERT(f3() == 32);
75 #endif