Skip to content

Commit 0c53e7e

Browse files
committed
Add test case for bug cc65#2357
1 parent db8ac35 commit 0c53e7e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/val/bug2357.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* bug #2357 - Compiler produces invalid code after d8a3938
2+
*/
3+
4+
unsigned long test;
5+
6+
unsigned long longarray[7];
7+
8+
void jsr_threebytes(void) {
9+
10+
}
11+
12+
/* having replaced two sty $zp with two sta $abs, but forgetting
13+
* to update the instruction size, coptlong.c could cause a build
14+
* error "Error: Range error (131 not in [-128..127])" if the
15+
* computed codesize was under 126, but the real codesize was above
16+
* 127.
17+
* This tests verifies that the bug is fixed.
18+
*/
19+
unsigned char __fastcall__ foo (unsigned char res)
20+
{
21+
if (res == 0) {
22+
longarray[1]=test; /* 24 bytes - but the compiler thought 22 */
23+
longarray[2]=test; /* 48 bytes - but 44 */
24+
longarray[3]=test; /* 72 bytes - 66 */
25+
longarray[4]=test; /* 96 bytes - 88 */
26+
longarray[6]=test; /* 120 bytes - 110 */
27+
jsr_threebytes(); /* 123 - 113 */
28+
jsr_threebytes(); /* 126 - 116 */
29+
jsr_threebytes(); /* 129 - 119 */
30+
}
31+
return 0;
32+
}
33+
34+
int main (void)
35+
{
36+
foo(42);
37+
return 0;
38+
}

0 commit comments

Comments
 (0)