Skip to content

Pointer.load of an unboxed ADT causes failure in lowering #582

@eliotmoss

Description

@eliotmoss

This is the failure that occurred when building Wizard's unittest:

./build.sh unittest x86-64-linux
!BoundsCheckException
         in TupleNorm.getElem() [aeneas/src/ir/TypeNorm.v3 @ 118:47]
         in MachLowering.genTupleGetElem() [aeneas/src/mach/MachLowering.v3 @ 1756:39]
         in MachLowering.genApplyOp0() [aeneas/src/mach/MachLowering.v3 @ 535:87]
         in MachLowering.genApplyOp() [aeneas/src/mach/MachLowering.v3 @ 444:28]
         in MachLowering.doBlock() [aeneas/src/mach/MachLowering.v3 @ 393:51]
         in MachLowering.doMethod() [aeneas/src/mach/MachLowering.v3 @ 301:32]
         in MachProgram.build() [aeneas/src/mach/MachProgram.v3 @ 51:42]
         in LinuxTarget.emit() [aeneas/src/os/Linux.v3 @ 75:27]
         in Compilation.emit() [aeneas/src/main/Compiler.v3 @ 378:45]
         in Compilation.compile() [aeneas/src/main/Compiler.v3 @ 252:32]
         in Aeneas.compile() [aeneas/src/main/Aeneas.v3 @ 82:56]
         in Aeneas.main() [aeneas/src/main/Aeneas.v3 @ 25:39]

It comes from this method:

         def popContinuation() -> Continuation {
                 if (Continuations.valueKind == ValueKind.REF) {
                         var ptr = vsp + (valuerep.tag_size - valuerep.slot_size);
                         var cont = ptr.load<Continuation>();
                         vsp += -(valuerep.slot_size);
                         return cont;
                 } else {
                         var ptr = vsp + (valuerep.tag_size - valuerep.slot_size);
                         var stack = ptr.load<WasmStack>();
                         var version = (ptr + 8).load<u64>();
                         vsp += -(valuerep.slot_size);
                         return Continuations.continuationWithVersion(stack, version);
                 }
         }

While Continuations.valueKind is ValueKind.REF_U64, generation of SSA did not figure that out early enough to prevent generating SSA for the true branch of the if, so the Pointer.load was generated. It later fails during lowering, perhaps because of something normalization did or failed to do. The load should probably generate multiple loads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions