From a12e0ae2541320f8fe96a09e7fdfe7aea5a4e3ba Mon Sep 17 00:00:00 2001 From: illuminatedfellow <361192299+illuminatedfellow@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:01:00 +0200 Subject: [PATCH] ir::build: a scalar code past the registers is not an index past unspill's table unspill marks the scalar codes a program uses in a table of 128, but an instruction's effects can name a code up to 255 (a VOP3 compare whose sdst field holds a constant's code, e.g. 0xD4C5A8D7), which panicked with an index out of bounds instead of a translation error. The table now covers every code, as stores and other beside it already do. Found by fuzzing the translator (mutated test programs and random words through ir::build, structure, resources, io and lowering). Port of avatarmanz/VIctory-7900XTX#325; the new test panics on this main (index 215, len 128) and passes with the change. (cherry picked from commit d30f8bee17096cab6a6de3f5f37244211dcaa861) --- crates/victory-shader/src/ir.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/victory-shader/src/ir.rs b/crates/victory-shader/src/ir.rs index 6612464..65179f1 100644 --- a/crates/victory-shader/src/ir.rs +++ b/crates/victory-shader/src/ir.rs @@ -298,7 +298,7 @@ fn unspill( // per instruction the scalar codes it writes. let mut stores = [false; 256]; let mut other: [Option; 256] = [None; 256]; // the last such use - let mut used = [false; 128]; + let mut used = [false; 256]; let mut parks: Vec> = Vec::with_capacity(list.len()); let mut written: Vec> = Vec::with_capacity(list.len()); let mut read: Vec> = Vec::with_capacity(list.len()); @@ -1875,6 +1875,25 @@ mod tests { build(&code, wave64, 256).unwrap() } + /// A scalar destination field of 128 or more (a constant's code, not a + /// register) is refused or ignored, never an index past the scalar + /// codes the parking search keeps (found by fuzzing the translator). + #[test] + fn scalar_codes_past_the_registers_do_not_panic() { + // v_writelane_b32 v1, s0, 0: a program that parks a scalar, so the + // parking search runs. + const PARK: [u32; 2] = [0xD761_0001, 0x0001_0000]; + for (words, wave64) in [ + ([0xD4C5_A8D7, 0x9342_BFA0], true), + ([0xD401_53FF, 0x0509_8D04], false), + ([0xD4EC_FE8B, 0x1234_5678], false), + ] { + let words = [&PARK[..], &words[..], &[S_ENDPGM]].concat(); + let code: Vec = words.iter().flat_map(|w| w.to_le_bytes()).collect(); + let _ = build(&code, wave64, 256); + } + } + fn input(p: &Program, reg: Reg) -> Value { p.inputs.iter().find(|i| i.0 == reg).expect("input").1 }