* support/regression/tests/fetchoverlap.c: Added new test case.
[fw/sdcc] / support / regression / tests / fetchoverlap.c
1 /* Test to reproduce a bug in the z80 compiler where A is used as the
2    left and right of an operand.
3 */
4 #include <testfwk.h>
5 #include <string.h>
6
7 /* In the previous bug, both *p and val in the compare operation were
8    assigned into A due to *p being packed for ACC use into A.
9 */
10 int
11 verifyBlock(char *p, char val, int len)
12 {
13   while (len--) {
14     if (*p++ != val) {
15       return 0;
16     }
17   }
18   return 1;
19 }
20
21 void
22 testOverlap(void)
23 {
24   char buf[20];
25   memset(buf, 12, sizeof(buf));
26
27   buf[12] = 13;
28   ASSERT(!verifyBlock(buf, 12, sizeof(buf)));
29
30   buf[12] = 12;
31   ASSERT(verifyBlock(buf, 12, sizeof(buf)));
32 }
33