fix: zero-out sub-32 bit expressions

This commit is contained in:
Gleb Koval 2025-02-27 15:46:01 +00:00
parent 4ffe85be91
commit 82a3d6068b
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
2 changed files with 8 additions and 6 deletions

View File

@ -41,8 +41,6 @@ object asmGenerator {
private val RCX = Register(Q64, CX)
private val argRegs = List(DI, SI, DX, CX, R8, R9)
private val _8_BIT_MASK = 0xff
extension [T](chain: Chain[T])
def +(item: T): Chain[T] = chain.append(item)
@ -378,6 +376,7 @@ object asmGenerator {
}
assert(stack.size == stackSizeStart + 1)
chain ++= zeroRest(MemLocation(stack.head.pointer, Q64), expr.ty.size)
chain
}
@ -419,7 +418,7 @@ object asmGenerator {
chain += Compare(destX, stack.head)
chain += Set(Register(B8, AX), cond)
chain += And(RAX, ImmediateVal(_8_BIT_MASK))
chain ++= zeroRest(RAX, B8)
chain += stack.drop()
chain += stack.push(B8, RAX)
@ -442,6 +441,10 @@ object asmGenerator {
}
private def stackAlign: AsmLine = And(Register(Q64, SP), ImmediateVal(-16))
private def zeroRest(dest: Dest, size: Size): Chain[AsmLine] = size match {
case Q64 | D32 => Chain.empty
case _ => Chain.one(And(dest, ImmediateVal((1 << (size.toInt * 8)) - 1)))
}
private val escapedCharsMapping = escapedChars.map { case (k, v) => v -> s"\\$k" }
extension (s: String) {

View File

@ -93,14 +93,13 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll {
"^.*wacc-examples/valid/function/nested_functions.*$",
"^.*wacc-examples/valid/function/simple_functions.*$",
// "^.*wacc-examples/valid/if.*$",
"^.*wacc-examples/valid/IO/print.*$",
// "^.*wacc-examples/valid/IO/print.*$",
// "^.*wacc-examples/valid/IO/read.*$",
"^.*wacc-examples/valid/IO/IOLoop.wacc.*$",
// "^.*wacc-examples/valid/IO/IOSequence.wacc.*$",
"^.*wacc-examples/valid/pairs.*$",
// "^.*wacc-examples/valid/pairs.*$",
"^.*wacc-examples/valid/runtimeErr.*$",
// "^.*wacc-examples/valid/scope.*$",
"^.*wacc-examples/valid/scope/printAllTypes.wacc$", // while we still don't have arrays implemented
// "^.*wacc-examples/valid/sequence.*$",
// "^.*wacc-examples/valid/variables.*$",
// "^.*wacc-examples/valid/while.*$",