Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cranelift/codegen/src/ir/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ impl InstructionData {
/// `None`.
pub fn trap_code(&self) -> Option<TrapCode> {
match *self {
Self::CondTrap { code, .. } | Self::Trap { code, .. } => Some(code),
Self::CondTrap { code, .. }
| Self::IntAddTrap { code, .. }
| Self::Trap { code, .. } => Some(code),
_ => None,
}
}
Expand Down Expand Up @@ -519,7 +521,9 @@ impl InstructionData {
/// trap code. Otherwise, return `None`.
pub fn trap_code_mut(&mut self) -> Option<&mut TrapCode> {
match self {
Self::CondTrap { code, .. } | Self::Trap { code, .. } => Some(code),
Self::CondTrap { code, .. }
| Self::IntAddTrap { code, .. }
| Self::Trap { code, .. } => Some(code),
_ => None,
}
}
Expand Down
8 changes: 3 additions & 5 deletions cranelift/interpreter/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,10 @@ where
assign_multiple(&[sum, DataValueExt::bool(carry, false, types::I8)?])
}
Opcode::UaddOverflowTrap => {
let sum = DataValueExt::add(arg(0), arg(1))?;
let carry = sum < arg(0) && sum < arg(1);
if carry {
ControlFlow::Trap(CraneliftTrap::User(trap_code()))
} else {
if let Some(sum) = DataValueExt::uadd_checked(arg(0), arg(1))? {
assign(sum)
} else {
ControlFlow::Trap(CraneliftTrap::User(trap_code()))
}
}
Opcode::SsubOverflowBin => {
Expand Down
1 change: 1 addition & 0 deletions cranelift/src/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl FileInterpreter {
let state = InterpreterState::default().with_function_store(env.clone());
match Interpreter::new(state).call_by_name(func_name, args) {
Ok(ControlFlow::Return(results)) => Ok(results.to_vec()),
Ok(ControlFlow::Trap(trap)) => Err(trap.to_string()),
Ok(_) => panic!("Unexpected returned control flow--this is likely a bug."),
Err(t) => Err(t.to_string()),
}
Expand Down