cranelift: Fix br_table for i64 inputs
We still only support a maximum of u32::MAX entries, however we no longer crash when compiling 64 bit indexes. Fixes #3100
This commit is contained in:
@@ -7202,24 +7202,34 @@ impl LowerBackend for X64Backend {
|
|||||||
|
|
||||||
Opcode::BrTable => {
|
Opcode::BrTable => {
|
||||||
let jt_size = targets.len() - 1;
|
let jt_size = targets.len() - 1;
|
||||||
assert!(jt_size <= u32::max_value() as usize);
|
assert!(jt_size <= u32::MAX as usize);
|
||||||
let jt_size = jt_size as u32;
|
let jt_size = jt_size as u32;
|
||||||
|
|
||||||
|
let ty = ctx.input_ty(branches[0], 0);
|
||||||
|
let ext_spec = match ty {
|
||||||
|
types::I128 => panic!("BrTable unimplemented for I128"),
|
||||||
|
types::I64 => ExtSpec::ZeroExtendTo64,
|
||||||
|
_ => ExtSpec::ZeroExtendTo32,
|
||||||
|
};
|
||||||
|
|
||||||
let idx = extend_input_to_reg(
|
let idx = extend_input_to_reg(
|
||||||
ctx,
|
ctx,
|
||||||
InsnInput {
|
InsnInput {
|
||||||
insn: branches[0],
|
insn: branches[0],
|
||||||
input: 0,
|
input: 0,
|
||||||
},
|
},
|
||||||
ExtSpec::ZeroExtendTo32,
|
ext_spec,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Bounds-check (compute flags from idx - jt_size) and branch to default.
|
// Bounds-check (compute flags from idx - jt_size) and branch to default.
|
||||||
ctx.emit(Inst::cmp_rmi_r(
|
// We only support u32::MAX entries, but we compare the full 64 bit register
|
||||||
OperandSize::Size32,
|
// when doing the bounds check.
|
||||||
RegMemImm::imm(jt_size),
|
let cmp_size = if ty == types::I64 {
|
||||||
idx,
|
OperandSize::Size64
|
||||||
));
|
} else {
|
||||||
|
OperandSize::Size32
|
||||||
|
};
|
||||||
|
ctx.emit(Inst::cmp_rmi_r(cmp_size, RegMemImm::imm(jt_size), idx));
|
||||||
|
|
||||||
// Emit the compound instruction that does:
|
// Emit the compound instruction that does:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
test interpret
|
test interpret
|
||||||
test run
|
test run
|
||||||
target aarch64
|
target aarch64
|
||||||
|
target x86_64 machinst
|
||||||
target s390x
|
target s390x
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user