Fixed a bug that didn't preserve the accumulator's value when a simple 16-bit fetch-and-store is optimized. (#637)

Fix a 16-bit fetch-and-store cc65 optimizer bug.
This commit is contained in:
greg-king5
2018-05-12 13:46:16 -04:00
committed by GitHub
parent 2a78b9d3fe
commit ca31e3af1e
2 changed files with 58 additions and 23 deletions

36
test/val/assign-use1.c Normal file
View File

@@ -0,0 +1,36 @@
/*
!!DESCRIPTION!! Assign an int; then, do an operation that depends directly on that assignment.
!!ORIGIN!! cc65 regression tests
!!LICENCE!! Public Domain
!!AUTHOR!! Greg King
*/
#include <stdio.h>
static unsigned char failures = 0;
static unsigned int result;
static const unsigned int buffer = 0xABCD;
int main(void)
{
result = buffer;
/* Shift doesn't use high byte (X register); previous assignment should be optimized. */
result <<= 8;
if (result != 0xCD00) {
++failures;
printf("assign-use1: left shift is $%X, not $CD00.\n", result);
}
result = buffer;
/* Shift does use high byte; previous assignment shouldn't be optimized by OptStore5(). */
result >>= 8;
if (result != 0x00AB) {
++failures;
printf("assign-use1: right shift is $%X, not $00AB.\n", result);
}
return failures;
}