Skip to main content

function_with_load

Function function_with_load 

Source
pub fn function_with_load(ty: Type, offset: i32) -> (Function, Inst)
Expand description

Build a function fn(ptr) -> ty whose entry block contains a single load.<ty> instruction reading from (param0 + offset), followed by a return of the loaded value.

The pointer param is a 64-bit integer ([PTR_TY]) — see the constant’s rustdoc for why we don’t use a dedicated pointer type. offset is the byte displacement passed to Cranelift’s load instruction; the lowering pass extracts it via InstructionData::Load { offset, .. }.

MemFlags::trusted() is used so the lowering doesn’t have to model trap behaviour for the fixture — these tests are about IR shape, not trap semantics.