Skip to content

Commit

Permalink
Merge pull request cc65#2362 from colinleroy/fix-2357-bis
Browse files Browse the repository at this point in the history
Add test case for bug cc65#2357
  • Loading branch information
mrdudz authored Jan 16, 2024
2 parents 5e267cc + 0c53e7e commit 92ee03f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/val/bug2357.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* bug #2357 - Compiler produces invalid code after d8a3938
*/

unsigned long test;

unsigned long longarray[7];

void jsr_threebytes(void) {

}

/* having replaced two sty $zp with two sta $abs, but forgetting
* to update the instruction size, coptlong.c could cause a build
* error "Error: Range error (131 not in [-128..127])" if the
* computed codesize was under 126, but the real codesize was above
* 127.
* This tests verifies that the bug is fixed.
*/
unsigned char __fastcall__ foo (unsigned char res)
{
if (res == 0) {
longarray[1]=test; /* 24 bytes - but the compiler thought 22 */
longarray[2]=test; /* 48 bytes - but 44 */
longarray[3]=test; /* 72 bytes - 66 */
longarray[4]=test; /* 96 bytes - 88 */
longarray[6]=test; /* 120 bytes - 110 */
jsr_threebytes(); /* 123 - 113 */
jsr_threebytes(); /* 126 - 116 */
jsr_threebytes(); /* 129 - 119 */
}
return 0;
}

int main (void)
{
foo(42);
return 0;
}

0 comments on commit 92ee03f

Please sign in to comment.