Fix OptStackOps label migration case for toscmpbool, add test case
This commit is contained in:
@@ -1153,6 +1153,8 @@ static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer)
|
|||||||
|
|
||||||
/* Save lhs into zeropage */
|
/* Save lhs into zeropage */
|
||||||
AddStoreLhsA (D);
|
AddStoreLhsA (D);
|
||||||
|
/* AddStoreLhsA may have moved the OpIndex, recalculate insertion point to prevent label migration. */
|
||||||
|
D->IP = D->OpIndex + 1;
|
||||||
|
|
||||||
/* cmp */
|
/* cmp */
|
||||||
X = NewCodeEntry (OP65_CMP, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
|
X = NewCodeEntry (OP65_CMP, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
|
||||||
|
|||||||
40
test/val/bug1989.c
Normal file
40
test/val/bug1989.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
/* bug #1989 - OptStackOps Opt_a_toscmpbool bypassed a comparison, discovered in 544a49c */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
unsigned char i,r,j;
|
||||||
|
|
||||||
|
void fail() // for the r=0 case, the == comparison was getting jumped over by OptStackOps
|
||||||
|
{
|
||||||
|
if ((i & 0x1f) == (r ? 0 : 16)) j -=8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pass()
|
||||||
|
{
|
||||||
|
if ((i & 0x1f) == (unsigned char)(r ? 0 : 16)) j -= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test(unsigned char ti, unsigned char tr, unsigned char tj)
|
||||||
|
{
|
||||||
|
unsigned char rj;
|
||||||
|
i = ti;
|
||||||
|
r = tr;
|
||||||
|
j = tj;
|
||||||
|
pass();
|
||||||
|
rj = j;
|
||||||
|
i = ti;
|
||||||
|
r = tr;
|
||||||
|
j = tj;
|
||||||
|
fail();
|
||||||
|
if (j != rj) exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
test( 1,0,33);
|
||||||
|
test( 0,0,33);
|
||||||
|
test( 1,1,33);
|
||||||
|
test(16,1,33);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user