Skip to content

Commit e13c122

Browse files
authored
Merge pull request #2897 from veryl-lang/fix/synth-eval-constant-bits-shift
fix(synthesizer): guard eval_constant_bits shift for constants wider than 64 bits
2 parents 2a864f2 + 50a1510 commit e13c122

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

crates/synthesizer/src/conv.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,9 @@ fn eval_constant_bits(expr: &air::Expression, width: usize) -> Option<Vec<bool>>
11981198
let n = value.to_u64()?;
11991199
let mut bits = Vec::with_capacity(width);
12001200
for i in 0..width {
1201-
bits.push((n >> i) & 1 != 0);
1201+
// `n` fits in u64, so bits >= 64 are 0; the guard also avoids the
1202+
// `i >= 64` shift overflow (panic in debug, wrong mask in release).
1203+
bits.push(i < 64 && (n >> i) & 1 != 0);
12021204
}
12031205
return Some(bits);
12041206
}

0 commit comments

Comments
 (0)