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)
This commit is contained in:
1 parent
261078d78c
commit
a12e0ae254
1 file changed
+20
-1
@@ -298,7 +298,7 @@ fn unspill(
|
||||
// per instruction the scalar codes it writes.
|
||||
let mut stores = [false; 256];
|
||||
let mut other: [Option<usize>; 256] = [None; 256]; // the last such use
|
||||
let mut used = [false; 128];
|
||||
let mut used = [false; 256];
|
||||
let mut parks: Vec<Option<(bool, u8, u8, u32)>> = Vec::with_capacity(list.len());
|
||||
let mut written: Vec<Vec<u8>> = Vec::with_capacity(list.len());
|
||||
let mut read: Vec<Vec<u8>> = 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<u8> = 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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user