fixed compiler crash when assigning number larger than 65535

This commit is contained in:
Irmen de Jong 2022-01-23 01:44:16 +01:00
parent 3d1b0eb843
commit 7bb41a30ed
5 changed files with 38 additions and 20 deletions

View File

@ -451,6 +451,10 @@ internal class AstChecker(private val program: Program,
errors.err("typecasting a float value in-place makes no sense", assignment.value.position)
}
val numvalue = assignment.value.constValue(program)
if(numvalue!=null && targetDt.isKnown)
checkValueTypeAndRange(targetDt.getOr(DataType.UNDEFINED), numvalue)
super.visit(assignment)
}

View File

@ -145,11 +145,40 @@ class TestNumbers: FunSpec({
}
}
"""
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
val errors = ErrorReporterForTests()
compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "converted to float"
errors.errors[1] shouldContain "converted to float"
}
test("out of range number assignments") {
val src="""
main {
sub start() {
uword @shared qq = ${'$'}2ff33
cx16.r0 = ${'$'}1fc0f
}
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "out of range"
errors.errors[1] shouldContain "out of range"
}
test("big numbers okay in const expressions if result fits") {
val src="""
main {
sub start() {
uword @shared qq = ${'$'}2ff33 >> 4
cx16.r0 = ${'$'}1fc0f >> 4
}
}
"""
compileText(C64Target, true, src, writeAssembly = false).assertSuccess()
}
})

View File

@ -573,8 +573,9 @@ class TestOptimization: FunSpec({
"""
val errors = ErrorReporterForTests()
compileText(C64Target, optimize=true, src, writeAssembly=false, errors = errors).assertFailure()
errors.errors.size shouldBe 1
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "type of value BYTE doesn't match target UBYTE"
errors.errors[1] shouldContain "out of range"
}
test("test augmented expression asmgen") {

View File

@ -3,7 +3,6 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- FIx: cx16.r0 = $1fc0f compiler crash
- Fix: uword addr = label ; addr will be 0! required to use &label!
- Fix compiler stack overflow crash:
sub sprite_y_for_row(ubyte row) -> word {

View File

@ -3,22 +3,7 @@
main {
sub start() {
move()
}
sub move() {
ubyte mb = cx16.mouse_pos()
ubyte @shared xx = cx16.r0H
ubyte @shared yy = cx16.r0L
func(cx16.r0H)
func(cx16.r0L)
cx16.vpoke(1, $fc08+2, cx16.r0H)
cx16.vpoke(1, $fc08+3, cx16.r0L)
}
asmsub func(ubyte qq @A) {
%asm {{
rts
}}
uword @shared qq = $2ff33
cx16.r0 = $1fc0f
}
}