fix cpu stack corruption in array assignment codegen

This commit is contained in:
Irmen de Jong 2023-06-27 18:49:49 +02:00
parent 0a83b51e00
commit a9f5dc036c
3 changed files with 17 additions and 38 deletions

View File

@ -93,8 +93,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
SourceStorageKind.ARRAY -> inplaceModification_word_value_to_variable(target.asmVarname, target.datatype, operator, value.array!!)
SourceStorageKind.EXPRESSION -> {
if(value.expression is PtTypeCast) {
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator))
return
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) return
inplaceModification_word_value_to_variable(target.asmVarname, target.datatype, operator, value.expression)
}
else {
@ -271,8 +270,10 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
SourceStorageKind.ARRAY -> inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.array!!)
SourceStorageKind.EXPRESSION -> {
if(value.expression is PtTypeCast) {
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator))
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) {
asmgen.restoreRegisterLocal(CpuRegister.Y)
return
}
inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression)
} else {
inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression!!)
@ -301,8 +302,10 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
SourceStorageKind.ARRAY -> inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.array!!)
SourceStorageKind.EXPRESSION -> {
if(value.expression is PtTypeCast) {
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator))
if (tryInplaceModifyWithRemovedRedundantCast(value.expression, target, operator)) {
asmgen.restoreRegisterLocal(CpuRegister.Y)
return
}
inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression)
} else {
inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression!!)

View File

@ -1,6 +1,8 @@
TODO
====
- fix double code gen with tryInplaceModifyWithRemovedRedundantCast() ? word birdX[j] += testbyte
...

View File

@ -1,39 +1,13 @@
main
{
sub start()
{
ubyte variable=55
when variable
{
33 -> cx16.r0++
else -> cx16.r1++
}
%zeropage basicsafe
if variable {
cx16.r0++
} else {
cx16.r1++
}
main {
if variable { cx16.r0++ }
else { cx16.r1++ }
if variable
{
cx16.r0++
sub start() {
word[4] birdX
byte testbyte = 0
ubyte j = 0
repeat {
birdX[j] += testbyte
}
else
{
cx16.r1++
}
other.othersub()
}
}
other {
sub othersub() {
cx16.r0++
}
}