Skip to content

Register source locations for instructions that may load in x64 backend #2290

@abrown

Description

@abrown

Many instruction formats in the new x64 backend accept a RegMem parameter, implying that they may load from memory. This may cause a trap if the memory address is out-of-bounds and, in order to return the correct trap code, we should be registering the source location of the instruction, e.g.:

if let Some(srcloc) = *srcloc {
    sink.add_trap(srcloc, TrapCode::HeapOutOfBounds);
}

Currently, some formats do accept a RegMem parameter but do not correctly register the possible trap location. This passes the spec tests because these formats are not used in their RegMem::Mem variant, but for correctness and completeness we should register the trap locations any time it is possible that an instruction may load from memory.

The current convention for doing so appends a srcloc: Option<SourceLoc> field to the format and expects the programmer to correctly choose between None and Some(ctx.srcloc(insn)) when instatiating a new instruction format. I propose we change this: instead, attach the Option<SourceLoc>, or perhaps even a plain SourceLoc, to SyntheticAmode. This approach has advantages:

  • any programmer attempting to do a load/store will be forced to decide how the trap will be reported (but not when only accessing registers)
  • perhaps the helper functions in lower.rs can automatically attach a SourceLoc to any SyntheticAmodes created
  • the Inst formats no longer need an extra field filled with None in many cases

If we agree that the above approach is a good one, this issue should be closed not only

  1. when that refactoring is complete but
  2. also when any instruction formats that can load/store properly registers traps for their RegMem::Mem variants

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions