The main enhancement in this commit is support for reference types and stackmaps. This requires tracking whether each VReg is a "reference" or "pointer". At certain instructions designated as "safepoints", the regalloc will (i) ensure that all references are in spillslots rather than in registers, and (ii) provide a list of exactly which spillslots have live references at that program point. This can be used by, e.g., a GC to trace and possibly modify pointers. The stackmap of spillslots is precise: it includes all live references, and *only* live references. This commit also brings in some API tweaks as part of the in-progress Cranelift glue. In particular, it makes Allocations and Operands mutually disjoint by using the same bitfield for the type-tag in both and choosing non-overlapping tags. This will allow instructions to carry an Operand for each register slot and then overwrite these in place with Allocations. The `OperandOrAllocation` type does the necessary magic to make this look like an enum, but staying in 32 bits.
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
#![no_main]
|
|
use libfuzzer_sys::fuzz_target;
|
|
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured, Result};
|
|
|
|
use regalloc2::fuzzing::func::{Func, Options};
|
|
use regalloc2::checker::Checker;
|
|
|
|
#[derive(Clone, Debug)]
|
|
struct TestCase {
|
|
func: Func,
|
|
}
|
|
|
|
impl Arbitrary for TestCase {
|
|
fn arbitrary(u: &mut Unstructured) -> Result<TestCase> {
|
|
Ok(TestCase {
|
|
func: Func::arbitrary_with_options(u, &Options {
|
|
reused_inputs: true,
|
|
fixed_regs: true,
|
|
clobbers: true,
|
|
control_flow: true,
|
|
reducible: false,
|
|
block_params: true,
|
|
always_local_uses: false,
|
|
reftypes: true,
|
|
})?,
|
|
})
|
|
}
|
|
}
|
|
|
|
fuzz_target!(|testcase: TestCase| {
|
|
let func = testcase.func;
|
|
let _ = env_logger::try_init();
|
|
log::debug!("func:\n{:?}", func);
|
|
let env = regalloc2::fuzzing::func::machine_env();
|
|
let out = regalloc2::ion::run(&func, &env).expect("regalloc did not succeed");
|
|
|
|
let mut checker = Checker::new(&func);
|
|
checker.prepare(&out);
|
|
checker.run().expect("checker failed");
|
|
});
|