diff --git a/cranelift/codegen/src/isa/aarch64/inst/emit.rs b/cranelift/codegen/src/isa/aarch64/inst/emit.rs index 4f0288dc2b..04b9ba705f 100644 --- a/cranelift/codegen/src/isa/aarch64/inst/emit.rs +++ b/cranelift/codegen/src/isa/aarch64/inst/emit.rs @@ -3115,20 +3115,15 @@ impl MachInstEmit for Inst { sink.put4(enc_jump26(0b000101, not_taken.as_offset26_or_zero())); } &Inst::TrapIf { kind, trap_code } => { + let label = sink.defer_trap(trap_code, state.take_stack_map()); // condbr KIND, LABEL let off = sink.cur_offset(); - let label = sink.get_label(); sink.put4(enc_conditional_br( BranchTarget::Label(label), - kind.invert(), + kind, &mut allocs, )); sink.use_label_at_offset(off, label, LabelUse::Branch19); - // udf - let trap = Inst::Udf { trap_code }; - trap.emit(&[], sink, emit_info, state); - // LABEL: - sink.bind_label(label); } &Inst::IndirectBr { rn, .. } => { let rn = allocs.next(rn); @@ -3142,15 +3137,11 @@ impl MachInstEmit for Inst { sink.put4(0xd4200000); } &Inst::Udf { trap_code } => { - // "CLIF" in hex, to make the trap recognizable during - // debugging. - let encoding = 0xc11f; - sink.add_trap(trap_code); if let Some(s) = state.take_stack_map() { sink.add_stack_map(StackMapExtent::UpcomingBytes(4), s); } - sink.put4(encoding); + sink.put_data(Inst::TRAP_OPCODE); } &Inst::Adr { rd, off } => { let rd = allocs.next_writable(rd); diff --git a/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs b/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs index c0ba8ce1b1..fa5ab5068f 100644 --- a/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs +++ b/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs @@ -5873,144 +5873,144 @@ fn test_aarch64_binemit() { trap_code: TrapCode::Interrupt, kind: CondBrKind::NotZero(xreg(8)), }, - "480000B41FC10000", - "cbz x8, 8 ; udf", + "280000B51FC10000", + "cbnz x8, #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Zero(xreg(8)), }, - "480000B51FC10000", - "cbnz x8, 8 ; udf", + "280000B41FC10000", + "cbz x8, #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Ne), }, - "400000541FC10000", - "b.eq 8 ; udf", + "210000541FC10000", + "b.ne #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Eq), }, - "410000541FC10000", - "b.ne 8 ; udf", + "200000541FC10000", + "b.eq #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Lo), }, - "420000541FC10000", - "b.hs 8 ; udf", + "230000541FC10000", + "b.lo #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Hs), }, - "430000541FC10000", - "b.lo 8 ; udf", + "220000541FC10000", + "b.hs #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Pl), }, - "440000541FC10000", - "b.mi 8 ; udf", + "250000541FC10000", + "b.pl #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Mi), }, - "450000541FC10000", - "b.pl 8 ; udf", + "240000541FC10000", + "b.mi #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Vc), }, - "460000541FC10000", - "b.vs 8 ; udf", + "270000541FC10000", + "b.vc #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Vs), }, - "470000541FC10000", - "b.vc 8 ; udf", + "260000541FC10000", + "b.vs #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Ls), }, - "480000541FC10000", - "b.hi 8 ; udf", + "290000541FC10000", + "b.ls #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Hi), }, - "490000541FC10000", - "b.ls 8 ; udf", + "280000541FC10000", + "b.hi #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Lt), }, - "4A0000541FC10000", - "b.ge 8 ; udf", + "2B0000541FC10000", + "b.lt #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Ge), }, - "4B0000541FC10000", - "b.lt 8 ; udf", + "2A0000541FC10000", + "b.ge #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Le), }, - "4C0000541FC10000", - "b.gt 8 ; udf", + "2D0000541FC10000", + "b.le #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Gt), }, - "4D0000541FC10000", - "b.le 8 ; udf", + "2C0000541FC10000", + "b.gt #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Nv), }, - "4E0000541FC10000", - "b.al 8 ; udf", + "2F0000541FC10000", + "b.nv #trap=interrupt", )); insns.push(( Inst::TrapIf { trap_code: TrapCode::Interrupt, kind: CondBrKind::Cond(Cond::Al), }, - "4F0000541FC10000", - "b.nv 8 ; udf", + "2E0000541FC10000", + "b.al #trap=interrupt", )); insns.push(( diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rs index 22487b264e..09f64c7640 100644 --- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs +++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs @@ -926,6 +926,10 @@ impl MachInst for Inst { type ABIMachineSpec = AArch64MachineDeps; type LabelUse = LabelUse; + // "CLIF" in hex, to make the trap recognizable during + // debugging. + const TRAP_OPCODE: &'static [u8] = &0xc11f_u32.to_le_bytes(); + fn get_operands VReg>(&self, collector: &mut OperandCollector<'_, F>) { aarch64_get_operands(self, collector); } @@ -2519,18 +2523,21 @@ impl Inst { } &Inst::Brk => "brk #0".to_string(), &Inst::Udf { .. } => "udf #0xc11f".to_string(), - &Inst::TrapIf { ref kind, .. } => match kind { + &Inst::TrapIf { + ref kind, + trap_code, + } => match kind { &CondBrKind::Zero(reg) => { let reg = pretty_print_reg(reg, allocs); - format!("cbnz {}, 8 ; udf", reg) + format!("cbz {reg}, #trap={trap_code}") } &CondBrKind::NotZero(reg) => { let reg = pretty_print_reg(reg, allocs); - format!("cbz {}, 8 ; udf", reg) + format!("cbnz {reg}, #trap={trap_code}") } &CondBrKind::Cond(c) => { - let c = c.invert().pretty_print(0, allocs); - format!("b.{} 8 ; udf", c) + let c = c.pretty_print(0, allocs); + format!("b.{c} #trap={trap_code}") } }, &Inst::Adr { rd, off } => { diff --git a/cranelift/codegen/src/isa/riscv64/inst/emit.rs b/cranelift/codegen/src/isa/riscv64/inst/emit.rs index 74758aa184..d44d2d3066 100644 --- a/cranelift/codegen/src/isa/riscv64/inst/emit.rs +++ b/cranelift/codegen/src/isa/riscv64/inst/emit.rs @@ -1908,9 +1908,7 @@ impl MachInstEmit for Inst { if let Some(s) = state.take_stack_map() { sink.add_stack_map(StackMapExtent::UpcomingBytes(4), s); } - // https://github.com/riscv/riscv-isa-manual/issues/850 - // all zero will cause invalid opcode. - sink.put4(0); + sink.put_data(Inst::TRAP_OPCODE); } &Inst::SelectIf { if_spectre_guard: _if_spectre_guard, // _if_spectre_guard not use because it is used to not be removed by optimization pass and some other staff. diff --git a/cranelift/codegen/src/isa/riscv64/inst/mod.rs b/cranelift/codegen/src/isa/riscv64/inst/mod.rs index d7fbb6ca94..8ad8a4f13b 100644 --- a/cranelift/codegen/src/isa/riscv64/inst/mod.rs +++ b/cranelift/codegen/src/isa/riscv64/inst/mod.rs @@ -642,6 +642,10 @@ impl MachInst for Inst { type LabelUse = LabelUse; type ABIMachineSpec = Riscv64MachineDeps; + // https://github.com/riscv/riscv-isa-manual/issues/850 + // all zero will cause invalid opcode. + const TRAP_OPCODE: &'static [u8] = &[0; 4]; + fn gen_dummy_use(reg: Reg) -> Self { Inst::DummyUse { reg } } diff --git a/cranelift/codegen/src/isa/s390x/inst/mod.rs b/cranelift/codegen/src/isa/s390x/inst/mod.rs index 7305b98fbb..f6b22aa460 100644 --- a/cranelift/codegen/src/isa/s390x/inst/mod.rs +++ b/cranelift/codegen/src/isa/s390x/inst/mod.rs @@ -998,6 +998,7 @@ fn s390x_get_operands VReg>(inst: &Inst, collector: &mut OperandC impl MachInst for Inst { type ABIMachineSpec = S390xMachineDeps; type LabelUse = LabelUse; + const TRAP_OPCODE: &'static [u8] = &[0, 0]; fn get_operands VReg>(&self, collector: &mut OperandCollector<'_, F>) { s390x_get_operands(self, collector); diff --git a/cranelift/codegen/src/isa/x64/inst/emit.rs b/cranelift/codegen/src/isa/x64/inst/emit.rs index 3e19d33440..6c1dfc9fea 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit.rs @@ -1681,16 +1681,8 @@ pub(crate) fn emit( } Inst::TrapIf { cc, trap_code } => { - let else_label = sink.get_label(); - - // Jump over if the invert of CC is set (i.e. CC is not set). - one_way_jmp(sink, cc.invert(), else_label); - - // Trap! - let inst = Inst::trap(*trap_code); - inst.emit(&[], sink, info, state); - - sink.bind_label(else_label); + let trap_label = sink.defer_trap(*trap_code, state.take_stack_map()); + one_way_jmp(sink, *cc, trap_label); } Inst::TrapIfAnd { @@ -1698,15 +1690,13 @@ pub(crate) fn emit( cc2, trap_code, } => { + let trap_label = sink.defer_trap(*trap_code, state.take_stack_map()); let else_label = sink.get_label(); - // Jump over if either condition code is not set. + // Jump to the end if the first condition isn't true, and then if + // the second condition is true go to the trap. one_way_jmp(sink, cc1.invert(), else_label); - one_way_jmp(sink, cc2.invert(), else_label); - - // Trap! - let inst = Inst::trap(*trap_code); - inst.emit(&[], sink, info, state); + one_way_jmp(sink, *cc2, trap_label); sink.bind_label(else_label); } @@ -1716,19 +1706,11 @@ pub(crate) fn emit( cc2, trap_code, } => { - let trap_label = sink.get_label(); - let else_label = sink.get_label(); + let trap_label = sink.defer_trap(*trap_code, state.take_stack_map()); - // trap immediately if cc1 is set, otherwise jump over the trap if cc2 is not. + // Emit two jumps to the same trap if either condition code is true. one_way_jmp(sink, *cc1, trap_label); - one_way_jmp(sink, cc2.invert(), else_label); - - // Trap! - sink.bind_label(trap_label); - let inst = Inst::trap(*trap_code); - inst.emit(&[], sink, info, state); - - sink.bind_label(else_label); + one_way_jmp(sink, *cc2, trap_label); } Inst::XmmUnaryRmR { op, src, dst } => { @@ -3056,7 +3038,6 @@ pub(crate) fn emit( }; let done = sink.get_label(); - let not_nan = sink.get_label(); // The truncation. let inst = Inst::xmm_to_gpr(trunc_op, src, Writable::from_reg(dst), *dst_size); @@ -3073,9 +3054,10 @@ pub(crate) fn emit( let inst = Inst::xmm_cmp_rm_r(cmp_op, RegMem::reg(src), src); inst.emit(&[], sink, info, state); - one_way_jmp(sink, CC::NP, not_nan); // go to not_nan if not a NaN - if *is_saturating { + let not_nan = sink.get_label(); + one_way_jmp(sink, CC::NP, not_nan); // go to not_nan if not a NaN + // For NaN, emit 0. let inst = Inst::alu_rmi_r( *dst_size, @@ -3119,9 +3101,7 @@ pub(crate) fn emit( inst.emit(&[], sink, info, state); } } else { - let check_positive = sink.get_label(); - - let inst = Inst::trap(TrapCode::BadConversionToInteger); + let inst = Inst::trap_if(CC::P, TrapCode::BadConversionToInteger); inst.emit(&[], sink, info, state); // Check if INT_MIN was the correct result: determine the smallest floating point @@ -3130,8 +3110,6 @@ pub(crate) fn emit( // If the src register is less (or in some cases, less-or-equal) than the threshold, // trap! - sink.bind_label(not_nan); - let mut no_overflow_cc = CC::NB; // >= let output_bits = dst_size.to_bits(); match *src_size { @@ -3168,16 +3146,12 @@ pub(crate) fn emit( let inst = Inst::xmm_cmp_rm_r(cmp_op, RegMem::reg(tmp_xmm), src); inst.emit(&[], sink, info, state); - // jump over trap if src >= or > threshold - one_way_jmp(sink, no_overflow_cc, check_positive); - - let inst = Inst::trap(TrapCode::IntegerOverflow); + // no trap if src >= or > threshold + let inst = Inst::trap_if(no_overflow_cc.invert(), TrapCode::IntegerOverflow); inst.emit(&[], sink, info, state); // If positive, it was a real overflow. - sink.bind_label(check_positive); - // Zero out the tmp_xmm register. let inst = Inst::xmm_rm_r( SseOpcode::Xorpd, @@ -3189,9 +3163,8 @@ pub(crate) fn emit( let inst = Inst::xmm_cmp_rm_r(cmp_op, RegMem::reg(src), tmp_xmm); inst.emit(&[], sink, info, state); - one_way_jmp(sink, CC::NB, done); // jump over trap if 0 >= src - - let inst = Inst::trap(TrapCode::IntegerOverflow); + // no trap if 0 >= src + let inst = Inst::trap_if(CC::B, TrapCode::IntegerOverflow); inst.emit(&[], sink, info, state); } @@ -3291,11 +3264,10 @@ pub(crate) fn emit( let handle_large = sink.get_label(); one_way_jmp(sink, CC::NB, handle_large); // jump to handle_large if src >= large_threshold - let not_nan = sink.get_label(); - one_way_jmp(sink, CC::NP, not_nan); // jump over trap if not NaN - if *is_saturating { - // Emit 0. + // If not NaN jump over this 0-return, otherwise return 0 + let not_nan = sink.get_label(); + one_way_jmp(sink, CC::NP, not_nan); let inst = Inst::alu_rmi_r( *dst_size, AluRmiROpcode::Xor, @@ -3306,14 +3278,13 @@ pub(crate) fn emit( let inst = Inst::jmp_known(done); inst.emit(&[], sink, info, state); + sink.bind_label(not_nan); } else { // Trap. - let inst = Inst::trap(TrapCode::BadConversionToInteger); + let inst = Inst::trap_if(CC::P, TrapCode::BadConversionToInteger); inst.emit(&[], sink, info, state); } - sink.bind_label(not_nan); - // Actual truncation for small inputs: if the result is not positive, then we had an // overflow. @@ -3360,10 +3331,10 @@ pub(crate) fn emit( let inst = Inst::cmp_rmi_r(*dst_size, RegMemImm::imm(0), dst); inst.emit(&[], sink, info, state); - let next_is_large = sink.get_label(); - one_way_jmp(sink, CC::NL, next_is_large); // if dst >= 0, jump to next_is_large - if *is_saturating { + let next_is_large = sink.get_label(); + one_way_jmp(sink, CC::NL, next_is_large); // if dst >= 0, jump to next_is_large + // The input was "large" (>= 2**(width -1)), so the only way to get an integer // overflow is because the input was too large: saturate to the max value. let inst = Inst::imm( @@ -3379,13 +3350,12 @@ pub(crate) fn emit( let inst = Inst::jmp_known(done); inst.emit(&[], sink, info, state); + sink.bind_label(next_is_large); } else { - let inst = Inst::trap(TrapCode::IntegerOverflow); + let inst = Inst::trap_if(CC::L, TrapCode::IntegerOverflow); inst.emit(&[], sink, info, state); } - sink.bind_label(next_is_large); - if *dst_size == OperandSize::Size64 { let inst = Inst::imm(OperandSize::Size64, 1 << 63, Writable::from_reg(tmp_gpr)); inst.emit(&[], sink, info, state); @@ -3615,8 +3585,7 @@ pub(crate) fn emit( if let Some(s) = state.take_stack_map() { sink.add_stack_map(StackMapExtent::UpcomingBytes(2), s); } - sink.put1(0x0f); - sink.put1(0x0b); + sink.put_data(Inst::TRAP_OPCODE); } Inst::VirtualSPOffsetAdj { offset } => { diff --git a/cranelift/codegen/src/isa/x64/inst/mod.rs b/cranelift/codegen/src/isa/x64/inst/mod.rs index 84455dc208..179368430c 100644 --- a/cranelift/codegen/src/isa/x64/inst/mod.rs +++ b/cranelift/codegen/src/isa/x64/inst/mod.rs @@ -472,6 +472,10 @@ impl Inst { Inst::Ud2 { trap_code } } + pub(crate) fn trap_if(cc: CC, trap_code: TrapCode) -> Inst { + Inst::TrapIf { cc, trap_code } + } + pub(crate) fn cmove(size: OperandSize, cc: CC, src: RegMem, dst: Writable) -> Inst { debug_assert!(size.is_one_of(&[ OperandSize::Size16, @@ -1675,7 +1679,7 @@ impl PrettyPrint for Inst { } Inst::TrapIf { cc, trap_code, .. } => { - format!("j{} ; ud2 {} ;", cc.invert().to_string(), trap_code) + format!("j{cc} #trap={trap_code}") } Inst::TrapIfAnd { @@ -2502,6 +2506,8 @@ impl MachInst for Inst { } type LabelUse = LabelUse; + + const TRAP_OPCODE: &'static [u8] = &[0x0f, 0x0b]; } /// State carried between emissions of a sequence of instructions. diff --git a/cranelift/codegen/src/machinst/buffer.rs b/cranelift/codegen/src/machinst/buffer.rs index 6dc2518456..895f5e5ffd 100644 --- a/cranelift/codegen/src/machinst/buffer.rs +++ b/cranelift/codegen/src/machinst/buffer.rs @@ -229,6 +229,8 @@ pub struct MachBuffer { label_aliases: SmallVec<[MachLabel; 16]>, /// Constants that must be emitted at some point. pending_constants: SmallVec<[MachLabelConstant; 16]>, + /// Traps that must be emitted at some point. + pending_traps: SmallVec<[MachLabelTrap; 16]>, /// Fixups that must be performed after all code is emitted. fixup_records: SmallVec<[MachLabelFixup; 16]>, /// Current deadline at which all constants are flushed and all code labels @@ -371,6 +373,7 @@ impl MachBuffer { label_offsets: SmallVec::new(), label_aliases: SmallVec::new(), pending_constants: SmallVec::new(), + pending_traps: SmallVec::new(), fixup_records: SmallVec::new(), island_deadline: UNKNOWN_LABEL_OFFSET, island_worst_case_size: 0, @@ -1077,15 +1080,41 @@ impl MachBuffer { align, label ); - let deadline = self.cur_offset().saturating_add(max_distance); - self.island_worst_case_size += data.len() as CodeOffset; - self.island_worst_case_size = - (self.island_worst_case_size + I::LabelUse::ALIGN - 1) & !(I::LabelUse::ALIGN - 1); + self.update_deadline(data.len(), max_distance); self.pending_constants.push(MachLabelConstant { label, align, data: SmallVec::from(data), }); + } + + /// Emit a trap at some point in the future with the specified code and + /// stack map. + /// + /// This function returns a [`MachLabel`] which will be the future address + /// of the trap. Jumps should refer to this label, likely by using the + /// [`MachBuffer::use_label_at_offset`] method, to get a relocation + /// patched in once the address of the trap is known. + /// + /// This will batch all traps into the end of the function. + pub fn defer_trap(&mut self, code: TrapCode, stack_map: Option) -> MachLabel { + let label = self.get_label(); + self.update_deadline(I::TRAP_OPCODE.len(), u32::MAX); + self.pending_traps.push(MachLabelTrap { + label, + code, + stack_map, + loc: self.cur_srcloc.map(|(_start, loc)| loc), + }); + label + } + + fn update_deadline(&mut self, len: usize, max_distance: CodeOffset) { + trace!("defer: eventually emit {} bytes", len); + let deadline = self.cur_offset().saturating_add(max_distance); + self.island_worst_case_size += len as CodeOffset; + self.island_worst_case_size = + (self.island_worst_case_size + I::LabelUse::ALIGN - 1) & !(I::LabelUse::ALIGN - 1); if deadline < self.island_deadline { self.island_deadline = deadline; } @@ -1131,8 +1160,48 @@ impl MachBuffer { self.island_deadline = UNKNOWN_LABEL_OFFSET; self.island_worst_case_size = 0; - // First flush out all constants so we have more labels in case fixups - // are applied against these labels. + // End the current location tracking since anything emitted during this + // function shouldn't be attributed to whatever the current source + // location is. + // + // Note that the current source location, if it's set right now, will be + // restored at the end of this island emission. + let cur_loc = self.cur_srcloc.map(|(_, loc)| loc); + if cur_loc.is_some() { + self.end_srcloc(); + } + + // First flush out all traps/constants so we have more labels in case + // fixups are applied against these labels. + // + // Note that traps are placed first since this typically happens at the + // end of the function and for disassemblers we try to keep all the code + // contiguously together. + for MachLabelTrap { + label, + code, + stack_map, + loc, + } in mem::take(&mut self.pending_traps) + { + // If this trap has source information associated with it then + // emit this information for the trap instruction going out now too. + if let Some(loc) = loc { + self.start_srcloc(loc); + } + self.align_to(I::LabelUse::ALIGN); + self.bind_label(label); + self.add_trap(code); + if let Some(map) = stack_map { + let extent = StackMapExtent::UpcomingBytes(I::TRAP_OPCODE.len() as u32); + self.add_stack_map(extent, map); + } + self.put_data(I::TRAP_OPCODE); + if loc.is_some() { + self.end_srcloc(); + } + } + for MachLabelConstant { label, align, data } in mem::take(&mut self.pending_constants) { self.align_to(align); self.bind_label(label); @@ -1209,6 +1278,10 @@ impl MachBuffer { } } } + + if let Some(loc) = cur_loc { + self.start_srcloc(loc); + } } /// Emits a "veneer" the `kind` code at `offset` to jump to `label`. @@ -1256,7 +1329,10 @@ impl MachBuffer { } fn finish_emission_maybe_forcing_veneers(&mut self, force_veneers: bool) { - while !self.pending_constants.is_empty() || !self.fixup_records.is_empty() { + while !self.pending_constants.is_empty() + || !self.pending_traps.is_empty() + || !self.fixup_records.is_empty() + { // `emit_island()` will emit any pending veneers and constants, and // as a side-effect, will also take care of any fixups with resolved // labels eagerly. @@ -1479,6 +1555,19 @@ struct MachLabelConstant { data: SmallVec<[u8; 16]>, } +/// A trap that is deferred to the next time an island is emitted for either +/// traps, constants, or fixups. +struct MachLabelTrap { + /// This label will refer to the trap's offset. + label: MachLabel, + /// The code associated with this trap. + code: TrapCode, + /// An optional stack map to associate with this trap. + stack_map: Option, + /// An optional source location to assign for this trap. + loc: Option, +} + /// A fixup to perform on the buffer once code is emitted. Fixups always refer /// to labels and patch the code based on label offsets. Hence, they are like /// relocations, but internal to one buffer. @@ -1748,20 +1837,20 @@ mod test { buf.bind_label(label(0)); let inst = Inst::CondBr { - kind: CondBrKind::NotZero(xreg(0)), + kind: CondBrKind::Zero(xreg(0)), taken: target(1), not_taken: target(2), }; inst.emit(&[], &mut buf, &info, &mut state); buf.bind_label(label(1)); - let inst = Inst::Udf { - trap_code: TrapCode::Interrupt, - }; + let inst = Inst::Nop4; inst.emit(&[], &mut buf, &info, &mut state); buf.bind_label(label(2)); - let inst = Inst::Nop4; + let inst = Inst::Udf { + trap_code: TrapCode::Interrupt, + }; inst.emit(&[], &mut buf, &info, &mut state); buf.bind_label(label(3)); diff --git a/cranelift/codegen/src/machinst/mod.rs b/cranelift/codegen/src/machinst/mod.rs index 28738c9e61..895ea38626 100644 --- a/cranelift/codegen/src/machinst/mod.rs +++ b/cranelift/codegen/src/machinst/mod.rs @@ -177,6 +177,10 @@ pub trait MachInst: Clone + Debug { /// A label-use kind: a type that describes the types of label references that /// can occur in an instruction. type LabelUse: MachInstLabelUse; + + /// Byte representation of a trap opcode which is inserted by `MachBuffer` + /// during its `defer_trap` method. + const TRAP_OPCODE: &'static [u8]; } /// A descriptor of a label reference (use) in an instruction set. diff --git a/cranelift/filetests/filetests/isa/aarch64/arithmetic.clif b/cranelift/filetests/filetests/isa/aarch64/arithmetic.clif index 7084651da7..1f10db51fe 100644 --- a/cranelift/filetests/filetests/isa/aarch64/arithmetic.clif +++ b/cranelift/filetests/filetests/isa/aarch64/arithmetic.clif @@ -90,23 +90,23 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: -; cbnz x1, 8 ; udf +; cbz x1, #trap=int_divz ; adds xzr, x1, #1 ; ccmp x0, #1, #nzcv, eq -; b.vc 8 ; udf +; b.vs #trap=int_ovf ; sdiv x0, x0, x1 ; ret ; ; Disassembled: ; block0: ; offset 0x0 -; cbnz x1, #8 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x1, #0x18 ; cmn x1, #1 ; ccmp x0, #1, #0, eq -; b.vc #0x18 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.vs #0x1c ; sdiv x0, x0, x1 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f7(i64) -> i64 { block0(v0: i64): @@ -135,16 +135,16 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: -; cbnz x1, 8 ; udf +; cbz x1, #trap=int_divz ; udiv x0, x0, x1 ; ret ; ; Disassembled: ; block0: ; offset 0x0 -; cbnz x1, #8 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x1, #0xc ; udiv x0, x0, x1 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f9(i64) -> i64 { block0(v0: i64): @@ -173,18 +173,18 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: -; cbnz x1, 8 ; udf +; cbz x1, #trap=int_divz ; sdiv x4, x0, x1 ; msub x0, x4, x1, x0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 -; cbnz x1, #8 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x1, #0x10 ; sdiv x4, x0, x1 ; msub x0, x4, x1, x0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f11(i64, i64) -> i64 { block0(v0: i64, v1: i64): @@ -194,18 +194,18 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: -; cbnz x1, 8 ; udf +; cbz x1, #trap=int_divz ; udiv x4, x0, x1 ; msub x0, x4, x1, x0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 -; cbnz x1, #8 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x1, #0x10 ; udiv x4, x0, x1 ; msub x0, x4, x1, x0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f12(i32, i32) -> i32 { block0(v0: i32, v1: i32): @@ -217,10 +217,10 @@ block0(v0: i32, v1: i32): ; block0: ; sxtw x3, w0 ; sxtw x5, w1 -; cbnz x5, 8 ; udf +; cbz x5, #trap=int_divz ; adds wzr, w5, #1 ; ccmp w3, #1, #nzcv, eq -; b.vc 8 ; udf +; b.vs #trap=int_ovf ; sdiv x0, x3, x5 ; ret ; @@ -228,14 +228,14 @@ block0(v0: i32, v1: i32): ; block0: ; offset 0x0 ; sxtw x3, w0 ; sxtw x5, w1 -; cbnz x5, #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x5, #0x20 ; cmn w5, #1 ; ccmp w3, #1, #0, eq -; b.vc #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.vs #0x24 ; sdiv x0, x3, x5 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f13(i32) -> i32 { block0(v0: i32): @@ -268,7 +268,7 @@ block0(v0: i32, v1: i32): ; block0: ; mov w3, w0 ; mov w5, w1 -; cbnz x5, 8 ; udf +; cbz x5, #trap=int_divz ; udiv x0, x3, x5 ; ret ; @@ -276,10 +276,10 @@ block0(v0: i32, v1: i32): ; block0: ; offset 0x0 ; mov w3, w0 ; mov w5, w1 -; cbnz x5, #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x5, #0x14 ; udiv x0, x3, x5 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f15(i32) -> i32 { block0(v0: i32): @@ -312,7 +312,7 @@ block0(v0: i32, v1: i32): ; block0: ; sxtw x3, w0 ; sxtw x5, w1 -; cbnz x5, 8 ; udf +; cbz x5, #trap=int_divz ; sdiv x8, x3, x5 ; msub x0, x8, x5, x3 ; ret @@ -321,11 +321,11 @@ block0(v0: i32, v1: i32): ; block0: ; offset 0x0 ; sxtw x3, w0 ; sxtw x5, w1 -; cbnz x5, #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x5, #0x18 ; sdiv x8, x3, x5 ; msub x0, x8, x5, x3 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f17(i32, i32) -> i32 { block0(v0: i32, v1: i32): @@ -337,7 +337,7 @@ block0(v0: i32, v1: i32): ; block0: ; mov w3, w0 ; mov w5, w1 -; cbnz x5, 8 ; udf +; cbz x5, #trap=int_divz ; udiv x8, x3, x5 ; msub x0, x8, x5, x3 ; ret @@ -346,11 +346,11 @@ block0(v0: i32, v1: i32): ; block0: ; offset 0x0 ; mov w3, w0 ; mov w5, w1 -; cbnz x5, #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz +; cbz x5, #0x18 ; udiv x8, x3, x5 ; msub x0, x8, x5, x3 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_divz function %f18(i64, i64) -> i64 { block0(v0: i64, v1: i64): @@ -787,7 +787,7 @@ block0(v0: i64): ; movn x2, #0 ; adds xzr, x2, #1 ; ccmp x0, #1, #nzcv, eq -; b.vc 8 ; udf +; b.vs #trap=int_ovf ; sdiv x0, x0, x2 ; ret ; @@ -796,8 +796,8 @@ block0(v0: i64): ; mov x2, #-1 ; cmn x2, #1 ; ccmp x0, #1, #0, eq -; b.vc #0x14 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.vs #0x18 ; sdiv x0, x0, x2 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf diff --git a/cranelift/filetests/filetests/isa/aarch64/fcvt-small.clif b/cranelift/filetests/filetests/isa/aarch64/fcvt-small.clif index 1074c034af..7ec8be6a26 100644 --- a/cranelift/filetests/filetests/isa/aarch64/fcvt-small.clif +++ b/cranelift/filetests/filetests/isa/aarch64/fcvt-small.clif @@ -83,33 +83,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #17280, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x43800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function u0:0(f64) -> i8 { block0(v0: f64): @@ -120,33 +120,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16496, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x4070000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function u0:0(f32) -> i16 { block0(v0: f32): @@ -157,33 +157,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #18304, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x47800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function u0:0(f64) -> i16 { block0(v0: f64): @@ -194,31 +194,31 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16624, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x40f0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf diff --git a/cranelift/filetests/filetests/isa/aarch64/fcvt.clif b/cranelift/filetests/filetests/isa/aarch64/fcvt.clif index c17f495cc6..f313ebc2b2 100644 --- a/cranelift/filetests/filetests/isa/aarch64/fcvt.clif +++ b/cranelift/filetests/filetests/isa/aarch64/fcvt.clif @@ -237,33 +237,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #20352, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x4f800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f14(f32) -> i64 { block0(v0: f32): @@ -274,33 +274,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #24448, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu x0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x5f800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu x0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f15(f64) -> i32 { block0(v0: f64): @@ -311,33 +311,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16880, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x41f0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f16(f64) -> i64 { block0(v0: f64): @@ -348,33 +348,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #17392, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu x0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x43f0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu x0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f17(f32) -> i32 { block0(v0: f32): @@ -449,35 +449,35 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz w4, #52992, LSL #16 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz w10, #20224, LSL #16 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov w4, #-0x31000000 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov w10, #0x4f000000 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f22(f32) -> i64 { block0(v0: f32): @@ -488,35 +488,35 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz w4, #57088, LSL #16 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz w10, #24320, LSL #16 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs x0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov w4, #-0x21000000 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov w10, #0x5f000000 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs x0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f23(f64) -> i32 { block0(v0: f64): @@ -527,33 +527,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; ldr d4, [const(0)] ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16864, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; ldr d4, #0x38 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x41e0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzs w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf ; .byte 0x00, 0x00, 0x20, 0x00 ; .byte 0x00, 0x00, 0xe0, 0xc1 @@ -566,35 +566,35 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz x4, #50144, LSL #48 ; fmov d6, x4 ; fcmp d0, d6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz x10, #17376, LSL #48 ; fmov d20, x10 ; fcmp d0, d20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs x0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov x4, #-0x3c20000000000000 ; fmov d6, x4 ; fcmp d0, d6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov x10, #0x43e0000000000000 ; fmov d20, x10 ; fcmp d0, d20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs x0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f25(f32) -> i32 { block0(v0: f32): diff --git a/cranelift/filetests/filetests/isa/aarch64/floating-point.clif b/cranelift/filetests/filetests/isa/aarch64/floating-point.clif index 186b06ad90..db002a13ea 100644 --- a/cranelift/filetests/filetests/isa/aarch64/floating-point.clif +++ b/cranelift/filetests/filetests/isa/aarch64/floating-point.clif @@ -527,33 +527,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #20352, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x4f800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f34(f32) -> i32 { block0(v0: f32): @@ -564,35 +564,35 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz w4, #52992, LSL #16 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz w10, #20224, LSL #16 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs w0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov w4, #-0x31000000 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov w10, #0x4f000000 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs w0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f35(f32) -> i64 { block0(v0: f32): @@ -603,33 +603,33 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov s4, #-1 ; fcmp s0, s4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz w8, #24448, LSL #16 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu x0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov s4, #-1.00000000 ; fcmp s0, s4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov w8, #0x5f800000 ; fmov s18, w8 ; fcmp s0, s18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu x0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f36(f32) -> i64 { block0(v0: f32): @@ -640,35 +640,35 @@ block0(v0: f32): ; VCode: ; block0: ; fcmp s0, s0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz w4, #57088, LSL #16 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz w10, #24320, LSL #16 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs x0, s0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp s0, s0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov w4, #-0x21000000 ; fmov s6, w4 ; fcmp s0, s6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov w10, #0x5f000000 ; fmov s20, w10 ; fcmp s0, s20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs x0, s0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f37(f64) -> i32 { block0(v0: f64): @@ -679,33 +679,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16880, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x41f0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f38(f64) -> i32 { block0(v0: f64): @@ -716,33 +716,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; ldr d4, [const(0)] ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #16864, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs w0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; ldr d4, #0x38 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x41e0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzs w0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf ; .byte 0x00, 0x00, 0x20, 0x00 ; .byte 0x00, 0x00, 0xe0, 0xc1 @@ -755,33 +755,33 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; fmov d4, #-1 ; fcmp d0, d4 -; b.gt 8 ; udf +; b.le #trap=int_ovf ; movz x8, #17392, LSL #48 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzu x0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x2c ; fmov d4, #-1.00000000 ; fcmp d0, d4 -; b.gt #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.le #0x30 ; mov x8, #0x43f0000000000000 ; fmov d18, x8 ; fcmp d0, d18 -; b.lt #0x30 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x34 ; fcvtzu x0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f40(f64) -> i64 { block0(v0: f64): @@ -792,35 +792,35 @@ block0(v0: f64): ; VCode: ; block0: ; fcmp d0, d0 -; b.vc 8 ; udf +; b.vs #trap=bad_toint ; movz x4, #50144, LSL #48 ; fmov d6, x4 ; fcmp d0, d6 -; b.ge 8 ; udf +; b.lt #trap=int_ovf ; movz x10, #17376, LSL #48 ; fmov d20, x10 ; fcmp d0, d20 -; b.lt 8 ; udf +; b.ge #trap=int_ovf ; fcvtzs x0, d0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; fcmp d0, d0 -; b.vc #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; b.vs #0x30 ; mov x4, #-0x3c20000000000000 ; fmov d6, x4 ; fcmp d0, d6 -; b.ge #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.lt #0x34 ; mov x10, #0x43e0000000000000 ; fmov d20, x10 ; fcmp d0, d20 -; b.lt #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; b.ge #0x38 ; fcvtzs x0, d0 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: bad_toint +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: int_ovf function %f41(i32) -> f32 { block0(v0: i32): diff --git a/cranelift/filetests/filetests/isa/aarch64/stack-limit.clif b/cranelift/filetests/filetests/isa/aarch64/stack-limit.clif index e938e155a6..4e6fc52c02 100644 --- a/cranelift/filetests/filetests/isa/aarch64/stack-limit.clif +++ b/cranelift/filetests/filetests/isa/aarch64/stack-limit.clif @@ -56,7 +56,7 @@ block0(v0: i64): ; stp fp, lr, [sp, #-16]! ; mov fp, sp ; subs xzr, sp, x0, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; block0: ; load_ext_name x2, TestCase(%foo)+0 ; blr x2 @@ -68,16 +68,16 @@ block0(v0: i64): ; stp x29, x30, [sp, #-0x10]! ; mov x29, sp ; cmp sp, x0 -; b.hs #0x14 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf -; block1: ; offset 0x14 -; ldr x2, #0x1c -; b #0x24 +; b.lo #0x2c +; block1: ; offset 0x10 +; ldr x2, #0x18 +; b #0x20 ; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %foo 0 ; .byte 0x00, 0x00, 0x00, 0x00 ; blr x2 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %stack_limit_gv_call_zero(i64 vmctx) { gv0 = vmctx @@ -96,7 +96,7 @@ block0(v0: i64): ; ldr x16, [x0] ; ldr x16, [x16, #4] ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; block0: ; load_ext_name x2, TestCase(%foo)+0 ; blr x2 @@ -110,16 +110,16 @@ block0(v0: i64): ; ldur x16, [x0] ; ldur x16, [x16, #4] ; cmp sp, x16 -; b.hs #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf -; block1: ; offset 0x1c -; ldr x2, #0x24 -; b #0x2c +; b.lo #0x34 +; block1: ; offset 0x18 +; ldr x2, #0x20 +; b #0x28 ; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %foo 0 ; .byte 0x00, 0x00, 0x00, 0x00 ; blr x2 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %stack_limit(i64 stack_limit) { ss0 = explicit_slot 168 @@ -132,7 +132,7 @@ block0(v0: i64): ; mov fp, sp ; add x16, x0, #176 ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; sub sp, sp, #176 ; block0: ; add sp, sp, #176 @@ -145,13 +145,13 @@ block0(v0: i64): ; mov x29, sp ; add x16, x0, #0xb0 ; cmp sp, x16 -; b.hs #0x18 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x24 ; sub sp, sp, #0xb0 -; block1: ; offset 0x1c +; block1: ; offset 0x18 ; add sp, sp, #0xb0 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %huge_stack_limit(i64 stack_limit) { ss0 = explicit_slot 400000 @@ -163,12 +163,12 @@ block0(v0: i64): ; stp fp, lr, [sp, #-16]! ; mov fp, sp ; subs xzr, sp, x0, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; movz w17, #6784 ; movk w17, w17, #6, LSL #16 ; add x16, x0, x17, UXTX ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; movz w16, #6784 ; movk w16, w16, #6, LSL #16 ; sub sp, sp, x16, UXTX @@ -184,23 +184,23 @@ block0(v0: i64): ; stp x29, x30, [sp, #-0x10]! ; mov x29, sp ; cmp sp, x0 -; b.hs #0x14 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x44 ; mov w17, #0x1a80 ; movk w17, #6, lsl #16 ; add x16, x0, x17, uxtx ; cmp sp, x16 -; b.hs #0x2c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x48 ; mov w16, #0x1a80 ; movk w16, #6, lsl #16 ; sub sp, sp, x16 -; block1: ; offset 0x38 +; block1: ; offset 0x30 ; mov w16, #0x1a80 ; movk w16, #6, lsl #16 ; add sp, sp, x16 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %limit_preamble(i64 vmctx) { gv0 = vmctx @@ -219,7 +219,7 @@ block0(v0: i64): ; ldr x16, [x16, #4] ; add x16, x16, #32 ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; sub sp, sp, #32 ; block0: ; add sp, sp, #32 @@ -234,13 +234,13 @@ block0(v0: i64): ; ldur x16, [x16, #4] ; add x16, x16, #0x20 ; cmp sp, x16 -; b.hs #0x20 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x2c ; sub sp, sp, #0x20 -; block1: ; offset 0x24 +; block1: ; offset 0x20 ; add sp, sp, #0x20 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %limit_preamble_huge(i64 vmctx) { gv0 = vmctx @@ -258,12 +258,12 @@ block0(v0: i64): ; ldr x16, [x0] ; ldr x16, [x16, #4] ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; movz w17, #6784 ; movk w17, w17, #6, LSL #16 ; add x16, x16, x17, UXTX ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; movz w16, #6784 ; movk w16, w16, #6, LSL #16 ; sub sp, sp, x16, UXTX @@ -281,23 +281,23 @@ block0(v0: i64): ; ldur x16, [x0] ; ldur x16, [x16, #4] ; cmp sp, x16 -; b.hs #0x1c -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x4c ; mov w17, #0x1a80 ; movk w17, #6, lsl #16 ; add x16, x16, x17, uxtx ; cmp sp, x16 -; b.hs #0x34 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x50 ; mov w16, #0x1a80 ; movk w16, #6, lsl #16 ; sub sp, sp, x16 -; block1: ; offset 0x40 +; block1: ; offset 0x38 ; mov w16, #0x1a80 ; movk w16, #6, lsl #16 ; add sp, sp, x16 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf function %limit_preamble_huge_offset(i64 vmctx) { gv0 = vmctx @@ -314,7 +314,7 @@ block0(v0: i64): ; movz w16, #6784 ; movk w16, w16, #6, LSL #16 ; ldr x16, [x0, x16, SXTX] ; add x16, x16, #32 ; subs xzr, sp, x16, UXTX -; b.hs 8 ; udf +; b.lo #trap=stk_ovf ; sub sp, sp, #32 ; block0: ; add sp, sp, #32 @@ -330,11 +330,11 @@ block0(v0: i64): ; ldr x16, [x0, x16, sxtx] ; add x16, x16, #0x20 ; cmp sp, x16 -; b.hs #0x24 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf +; b.lo #0x30 ; sub sp, sp, #0x20 -; block1: ; offset 0x28 +; block1: ; offset 0x24 ; add sp, sp, #0x20 ; ldp x29, x30, [sp], #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf diff --git a/cranelift/filetests/filetests/isa/aarch64/traps.clif b/cranelift/filetests/filetests/isa/aarch64/traps.clif index c68d3ed01d..9245e3420a 100644 --- a/cranelift/filetests/filetests/isa/aarch64/traps.clif +++ b/cranelift/filetests/filetests/isa/aarch64/traps.clif @@ -23,13 +23,13 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: ; adds x3, x0, x1 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; adds x3, x0, x1 -; b.lo #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0xc ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 diff --git a/cranelift/filetests/filetests/isa/aarch64/uadd_overflow_trap.clif b/cranelift/filetests/filetests/isa/aarch64/uadd_overflow_trap.clif index c6abb4054e..85f939f7cd 100644 --- a/cranelift/filetests/filetests/isa/aarch64/uadd_overflow_trap.clif +++ b/cranelift/filetests/filetests/isa/aarch64/uadd_overflow_trap.clif @@ -12,16 +12,16 @@ block0(v0: i32): ; block0: ; movz w2, #127 ; adds w0, w0, w2 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; mov w2, #0x7f ; adds w0, w0, w2 -; b.lo #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 function %f1(i32) -> i32 { block0(v0: i32): @@ -34,16 +34,16 @@ block0(v0: i32): ; block0: ; movz w2, #127 ; adds w0, w2, w0 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; mov w2, #0x7f ; adds w0, w2, w0 -; b.lo #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 function %f2(i32, i32) -> i32 { block0(v0: i32, v1: i32): @@ -54,15 +54,15 @@ block0(v0: i32, v1: i32): ; VCode: ; block0: ; adds w0, w0, w1 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; adds w0, w0, w1 -; b.lo #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0xc ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 function %f3(i64) -> i64 { block0(v0: i64): @@ -75,16 +75,16 @@ block0(v0: i64): ; block0: ; movz x2, #127 ; adds x0, x0, x2 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; mov x2, #0x7f ; adds x0, x0, x2 -; b.lo #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 function %f3(i64) -> i64 { block0(v0: i64): @@ -97,16 +97,16 @@ block0(v0: i64): ; block0: ; movz x2, #127 ; adds x0, x2, x0 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; mov x2, #0x7f ; adds x0, x2, x0 -; b.lo #0x10 -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0x10 ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 function %f4(i64, i64) -> i64 { block0(v0: i64, v1: i64): @@ -117,13 +117,13 @@ block0(v0: i64, v1: i64): ; VCode: ; block0: ; adds x0, x0, x1 -; b.lo 8 ; udf +; b.hs #trap=user0 ; ret ; ; Disassembled: ; block0: ; offset 0x0 ; adds x0, x0, x1 -; b.lo #0xc -; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 +; b.hs #0xc ; ret +; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: user0 diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat index 7fa54a2ec5..5a0896f066 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat @@ -44,7 +44,7 @@ ;; mov w10, w0 ;; movn w9, #65531 ;; adds x11, x10, x9 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x12, [x2, #8] ;; subs xzr, x11, x12 ;; b.hi label3 ; b label1 @@ -64,7 +64,7 @@ ;; mov w10, w0 ;; movn w9, #65531 ;; adds x11, x10, x9 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x12, [x1, #8] ;; subs xzr, x11, x12 ;; b.hi label3 ; b label1 diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat index eefa432499..aae035a788 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat @@ -44,7 +44,7 @@ ;; mov w10, w0 ;; movn w9, #65534 ;; adds x11, x10, x9 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x12, [x2, #8] ;; subs xzr, x11, x12 ;; b.hi label3 ; b label1 @@ -64,7 +64,7 @@ ;; mov w10, w0 ;; movn w9, #65534 ;; adds x11, x10, x9 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x12, [x1, #8] ;; subs xzr, x11, x12 ;; b.hi label3 ; b label1 diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index 1045f257d3..b3cf735041 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -44,7 +44,7 @@ ;; mov w13, w0 ;; movn w12, #65531 ;; adds x14, x13, x12 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x15, [x2, #8] ;; ldr x2, [x2] ;; add x0, x2, x0, UXTW @@ -64,7 +64,7 @@ ;; mov w13, w0 ;; movn w12, #65531 ;; adds x14, x13, x12 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x15, [x1, #8] ;; ldr x1, [x1] ;; add x0, x1, x0, UXTW @@ -77,4 +77,4 @@ ;; ldr w0, [x0] ;; b label1 ;; block1: -;; ret \ No newline at end of file +;; ret diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index ee621302c6..830f9c4c95 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -44,7 +44,7 @@ ;; mov w13, w0 ;; movn w12, #65534 ;; adds x14, x13, x12 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x15, [x2, #8] ;; ldr x2, [x2] ;; add x0, x2, x0, UXTW @@ -64,7 +64,7 @@ ;; mov w13, w0 ;; movn w12, #65534 ;; adds x14, x13, x12 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x15, [x1, #8] ;; ldr x1, [x1] ;; add x0, x1, x0, UXTW @@ -77,4 +77,4 @@ ;; ldrb w0, [x0] ;; b label1 ;; block1: -;; ret \ No newline at end of file +;; ret diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat index 0f5c65c5fc..197800a6ea 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat @@ -43,7 +43,7 @@ ;; block0: ;; movn w8, #65531 ;; adds x10, x0, x8 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x11, [x2, #8] ;; subs xzr, x10, x11 ;; b.hi label3 ; b label1 @@ -62,7 +62,7 @@ ;; block0: ;; movn w8, #65531 ;; adds x10, x0, x8 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x11, [x1, #8] ;; subs xzr, x10, x11 ;; b.hi label3 ; b label1 diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat index 17b2df9a0c..9576e65c58 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat @@ -43,7 +43,7 @@ ;; block0: ;; movn w8, #65534 ;; adds x10, x0, x8 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x11, [x2, #8] ;; subs xzr, x10, x11 ;; b.hi label3 ; b label1 @@ -62,7 +62,7 @@ ;; block0: ;; movn w8, #65534 ;; adds x10, x0, x8 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x11, [x1, #8] ;; subs xzr, x10, x11 ;; b.hi label3 ; b label1 diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index 8a71b333a8..182b5e0452 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -43,7 +43,7 @@ ;; block0: ;; movn w11, #65531 ;; adds x13, x0, x11 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x14, [x2, #8] ;; ldr x15, [x2] ;; add x15, x15, x0 @@ -62,7 +62,7 @@ ;; block0: ;; movn w11, #65531 ;; adds x13, x0, x11 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x14, [x1, #8] ;; ldr x15, [x1] ;; add x15, x15, x0 @@ -75,4 +75,4 @@ ;; ldr w0, [x15] ;; b label1 ;; block1: -;; ret \ No newline at end of file +;; ret diff --git a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index 0457daf21e..6798d80bc3 100644 --- a/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/aarch64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -43,7 +43,7 @@ ;; block0: ;; movn w11, #65534 ;; adds x13, x0, x11 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x14, [x2, #8] ;; ldr x15, [x2] ;; add x15, x15, x0 @@ -62,7 +62,7 @@ ;; block0: ;; movn w11, #65534 ;; adds x13, x0, x11 -;; b.lo 8 ; udf +;; b.hs #trap=heap_oob ;; ldr x14, [x1, #8] ;; ldr x15, [x1] ;; add x15, x15, x0 @@ -75,4 +75,4 @@ ;; ldrb w0, [x15] ;; b label1 ;; block1: -;; ret \ No newline at end of file +;; ret diff --git a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index e21b828a26..1c1a1189a5 100644 --- a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -90,4 +90,4 @@ ;; lrv %r2, 0(%r3) ;; jg label1 ;; block1: -;; br %r14 \ No newline at end of file +;; br %r14 diff --git a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index 4d8ebec82b..9741ef2dff 100644 --- a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -90,4 +90,4 @@ ;; llc %r2, 0(%r3) ;; jg label1 ;; block1: -;; br %r14 \ No newline at end of file +;; br %r14 diff --git a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index a6189b33bb..86cec29b9d 100644 --- a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -86,4 +86,4 @@ ;; lrv %r2, 0(%r2) ;; jg label1 ;; block1: -;; br %r14 \ No newline at end of file +;; br %r14 diff --git a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index 4cfd07ea9d..be29d35262 100644 --- a/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/s390x/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -86,4 +86,4 @@ ;; llc %r2, 0(%r2) ;; jg label1 ;; block1: -;; br %r14 \ No newline at end of file +;; br %r14 diff --git a/cranelift/filetests/filetests/isa/x64/fcvt.clif b/cranelift/filetests/filetests/isa/x64/fcvt.clif index 1a4ab0cc15..8de67a78ab 100644 --- a/cranelift/filetests/filetests/isa/x64/fcvt.clif +++ b/cranelift/filetests/filetests/isa/x64/fcvt.clif @@ -405,23 +405,23 @@ block0(v0: f32): ; movl $0x4f000000, %r8d ; movd %r8d, %xmm3 ; ucomiss %xmm3, %xmm0 -; jae 0x2f -; jnp 0x20 -; ud2 ; trap: bad_toint +; jae 0x2d +; jp 0x4c ; cvttss2si %xmm0, %eax ; cmpl $0, %eax -; jge 0x4b +; jge 0x47 ; ud2 ; trap: int_ovf ; movaps %xmm0, %xmm4 ; subss %xmm3, %xmm4 ; cvttss2si %xmm4, %eax ; cmpl $0, %eax -; jge 0x45 -; ud2 ; trap: int_ovf +; jl 0x4e ; addl $0x80000000, %eax ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf function %f14(f32) -> i64 { block0(v0: f32): @@ -446,24 +446,24 @@ block0(v0: f32): ; movl $0x5f000000, %r8d ; movd %r8d, %xmm3 ; ucomiss %xmm3, %xmm0 -; jae 0x31 -; jnp 0x20 -; ud2 ; trap: bad_toint +; jae 0x2f +; jp 0x57 ; cvttss2si %xmm0, %rax ; cmpq $0, %rax -; jge 0x56 +; jge 0x52 ; ud2 ; trap: int_ovf ; movaps %xmm0, %xmm4 ; subss %xmm3, %xmm4 ; cvttss2si %xmm4, %rax ; cmpq $0, %rax -; jge 0x49 -; ud2 ; trap: int_ovf +; jl 0x59 ; movabsq $9223372036854775808, %r8 ; addq %r8, %rax ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf function %f15(f64) -> i32 { block0(v0: f64): @@ -488,23 +488,23 @@ block0(v0: f64): ; movabsq $0x41e0000000000000, %r8 ; movq %r8, %xmm3 ; ucomisd %xmm3, %xmm0 -; jae 0x34 -; jnp 0x25 -; ud2 ; trap: bad_toint +; jae 0x32 +; jp 0x51 ; cvttsd2si %xmm0, %eax ; cmpl $0, %eax -; jge 0x50 +; jge 0x4c ; ud2 ; trap: int_ovf ; movaps %xmm0, %xmm4 ; subsd %xmm3, %xmm4 ; cvttsd2si %xmm4, %eax ; cmpl $0, %eax -; jge 0x4a -; ud2 ; trap: int_ovf +; jl 0x53 ; addl $0x80000000, %eax ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf function %f16(f64) -> i64 { block0(v0: f64): @@ -529,24 +529,24 @@ block0(v0: f64): ; movabsq $0x43e0000000000000, %r8 ; movq %r8, %xmm3 ; ucomisd %xmm3, %xmm0 -; jae 0x36 -; jnp 0x25 -; ud2 ; trap: bad_toint +; jae 0x34 +; jp 0x5c ; cvttsd2si %xmm0, %rax ; cmpq $0, %rax -; jge 0x5b +; jge 0x57 ; ud2 ; trap: int_ovf ; movaps %xmm0, %xmm4 ; subsd %xmm3, %xmm4 ; cvttsd2si %xmm4, %rax ; cmpq $0, %rax -; jge 0x4e -; ud2 ; trap: int_ovf +; jl 0x5e ; movabsq $9223372036854775808, %r8 ; addq %r8, %rax ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf function %f17(f32) -> i32 { block0(v0: f32): @@ -748,22 +748,22 @@ block0(v0: f32): ; block1: ; offset 0x4 ; cvttss2si %xmm0, %eax ; cmpl $1, %eax -; jno 0x3f +; jno 0x39 ; ucomiss %xmm0, %xmm0 -; jnp 0x1c -; ud2 ; trap: bad_toint +; jp 0x3e ; movl $0xcf000000, %edx ; movd %edx, %xmm3 ; ucomiss %xmm3, %xmm0 -; jae 0x30 -; ud2 ; trap: int_ovf +; jb 0x40 ; xorpd %xmm3, %xmm3 ; ucomiss %xmm0, %xmm3 -; jae 0x3f -; ud2 ; trap: int_ovf +; jb 0x42 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf +; ud2 ; trap: int_ovf function %f22(f32) -> i64 { block0(v0: f32): @@ -787,22 +787,22 @@ block0(v0: f32): ; block1: ; offset 0x4 ; cvttss2si %xmm0, %rax ; cmpq $1, %rax -; jno 0x41 +; jno 0x3b ; ucomiss %xmm0, %xmm0 -; jnp 0x1e -; ud2 ; trap: bad_toint +; jp 0x40 ; movl $0xdf000000, %edx ; movd %edx, %xmm3 ; ucomiss %xmm3, %xmm0 -; jae 0x32 -; ud2 ; trap: int_ovf +; jb 0x42 ; xorpd %xmm3, %xmm3 ; ucomiss %xmm0, %xmm3 -; jae 0x41 -; ud2 ; trap: int_ovf +; jb 0x44 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf +; ud2 ; trap: int_ovf function %f23(f64) -> i32 { block0(v0: f64): @@ -826,22 +826,22 @@ block0(v0: f64): ; block1: ; offset 0x4 ; cvttsd2si %xmm0, %eax ; cmpl $1, %eax -; jno 0x48 +; jno 0x42 ; ucomisd %xmm0, %xmm0 -; jnp 0x1d -; ud2 ; trap: bad_toint +; jp 0x47 ; movabsq $13970166044105375744, %rdx ; movq %rdx, %xmm3 ; ucomisd %xmm3, %xmm0 -; ja 0x38 -; ud2 ; trap: int_ovf +; jbe 0x49 ; xorpd %xmm3, %xmm3 ; ucomisd %xmm0, %xmm3 -; jae 0x48 -; ud2 ; trap: int_ovf +; jb 0x4b ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf +; ud2 ; trap: int_ovf function %f24(f64) -> i64 { block0(v0: f64): @@ -865,22 +865,22 @@ block0(v0: f64): ; block1: ; offset 0x4 ; cvttsd2si %xmm0, %rax ; cmpq $1, %rax -; jno 0x4a +; jno 0x44 ; ucomisd %xmm0, %xmm0 -; jnp 0x1f -; ud2 ; trap: bad_toint +; jp 0x49 ; movabsq $14114281232179134464, %rdx ; movq %rdx, %xmm3 ; ucomisd %xmm3, %xmm0 -; jae 0x3a -; ud2 ; trap: int_ovf +; jb 0x4b ; xorpd %xmm3, %xmm3 ; ucomisd %xmm0, %xmm3 -; jae 0x4a -; ud2 ; trap: int_ovf +; jb 0x4d ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: bad_toint +; ud2 ; trap: int_ovf +; ud2 ; trap: int_ovf function %f25(f32) -> i32 { block0(v0: f32): diff --git a/cranelift/filetests/filetests/isa/x64/sdiv.clif b/cranelift/filetests/filetests/isa/x64/sdiv.clif index f20b17d0b4..3c2c3599a2 100644 --- a/cranelift/filetests/filetests/isa/x64/sdiv.clif +++ b/cranelift/filetests/filetests/isa/x64/sdiv.clif @@ -14,7 +14,7 @@ block0(v0: i8, v1: i8): ; movq %rdi, %rax ; cbw %al, %al ; testb %sil, %sil -; jnz ; ud2 int_divz ; +; jz #trap=int_divz ; idiv %al, %sil, %al ; trap=int_ovf ; movq %rbp, %rsp ; popq %rbp @@ -28,12 +28,12 @@ block0(v0: i8, v1: i8): ; movq %rdi, %rax ; cbtw ; testb %sil, %sil -; jne 0x14 -; ud2 ; trap: int_divz +; je 0x1a ; idivb %sil ; trap: int_ovf ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: int_divz function %f2(i16, i16) -> i16 { block0(v0: i16, v1: i16): @@ -48,7 +48,7 @@ block0(v0: i16, v1: i16): ; movq %rdi, %rax ; cwd %ax, %dx ; testw %si, %si -; jnz ; ud2 int_divz ; +; jz #trap=int_divz ; idiv %ax, %dx, %si, %ax, %dx ; trap=int_ovf ; movq %rbp, %rsp ; popq %rbp @@ -62,12 +62,12 @@ block0(v0: i16, v1: i16): ; movq %rdi, %rax ; cwtd ; testw %si, %si -; jne 0x14 -; ud2 ; trap: int_divz +; je 0x1a ; idivw %si ; trap: int_ovf ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: int_divz function %f3(i32, i32) -> i32 { block0(v0: i32, v1: i32): @@ -82,7 +82,7 @@ block0(v0: i32, v1: i32): ; movq %rdi, %rax ; cdq %eax, %edx ; testl %esi, %esi -; jnz ; ud2 int_divz ; +; jz #trap=int_divz ; idiv %eax, %edx, %esi, %eax, %edx ; trap=int_ovf ; movq %rbp, %rsp ; popq %rbp @@ -96,12 +96,12 @@ block0(v0: i32, v1: i32): ; movq %rdi, %rax ; cltd ; testl %esi, %esi -; jne 0x12 -; ud2 ; trap: int_divz +; je 0x17 ; idivl %esi ; trap: int_ovf ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: int_divz function %f4(i64, i64) -> i64 { block0(v0: i64, v1: i64): @@ -116,7 +116,7 @@ block0(v0: i64, v1: i64): ; movq %rdi, %rax ; cqo %rax, %rdx ; testq %rsi, %rsi -; jnz ; ud2 int_divz ; +; jz #trap=int_divz ; idiv %rax, %rdx, %rsi, %rax, %rdx ; trap=int_ovf ; movq %rbp, %rsp ; popq %rbp @@ -130,10 +130,10 @@ block0(v0: i64, v1: i64): ; movq %rdi, %rax ; cqto ; testq %rsi, %rsi -; jne 0x14 -; ud2 ; trap: int_divz +; je 0x1a ; idivq %rsi ; trap: int_ovf ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: int_divz diff --git a/cranelift/filetests/filetests/isa/x64/traps.clif b/cranelift/filetests/filetests/isa/x64/traps.clif index 2a5da8413f..99808298e9 100644 --- a/cranelift/filetests/filetests/isa/x64/traps.clif +++ b/cranelift/filetests/filetests/isa/x64/traps.clif @@ -31,7 +31,7 @@ block0(v0: i64, v1: i64): ; block0: ; movq %rdi, %rcx ; addq %rcx, %rsi, %rcx -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -43,9 +43,9 @@ block0(v0: i64, v1: i64): ; block1: ; offset 0x4 ; movq %rdi, %rcx ; addq %rsi, %rcx -; jae 0x12 -; ud2 ; trap: user0 +; jb 0x15 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 diff --git a/cranelift/filetests/filetests/isa/x64/uadd_overflow_trap.clif b/cranelift/filetests/filetests/isa/x64/uadd_overflow_trap.clif index a47db9ee11..24d2f2c8f5 100644 --- a/cranelift/filetests/filetests/isa/x64/uadd_overflow_trap.clif +++ b/cranelift/filetests/filetests/isa/x64/uadd_overflow_trap.clif @@ -14,7 +14,7 @@ block0(v0: i32): ; block0: ; movq %rdi, %rax ; addl %eax, $127, %eax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -26,11 +26,11 @@ block0(v0: i32): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addl $0x7f, %eax -; jae 0x12 -; ud2 ; trap: user0 +; jb 0x15 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 function %f1(i32) -> i32 { block0(v0: i32): @@ -45,7 +45,7 @@ block0(v0: i32): ; block0: ; movq %rdi, %rax ; addl %eax, $127, %eax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -57,11 +57,11 @@ block0(v0: i32): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addl $0x7f, %eax -; jae 0x12 -; ud2 ; trap: user0 +; jb 0x15 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 function %f2(i32, i32) -> i32 { block0(v0: i32, v1: i32): @@ -75,7 +75,7 @@ block0(v0: i32, v1: i32): ; block0: ; movq %rdi, %rax ; addl %eax, %esi, %eax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -87,11 +87,11 @@ block0(v0: i32, v1: i32): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addl %esi, %eax -; jae 0x11 -; ud2 ; trap: user0 +; jb 0x14 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 function %f3(i64) -> i64 { block0(v0: i64): @@ -106,7 +106,7 @@ block0(v0: i64): ; block0: ; movq %rdi, %rax ; addq %rax, $127, %rax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -118,11 +118,11 @@ block0(v0: i64): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addq $0x7f, %rax -; jae 0x13 -; ud2 ; trap: user0 +; jb 0x16 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 function %f3(i64) -> i64 { block0(v0: i64): @@ -137,7 +137,7 @@ block0(v0: i64): ; block0: ; movq %rdi, %rax ; addq %rax, $127, %rax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -149,11 +149,11 @@ block0(v0: i64): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addq $0x7f, %rax -; jae 0x13 -; ud2 ; trap: user0 +; jb 0x16 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 function %f4(i64, i64) -> i64 { block0(v0: i64, v1: i64): @@ -167,7 +167,7 @@ block0(v0: i64, v1: i64): ; block0: ; movq %rdi, %rax ; addq %rax, %rsi, %rax -; jnb ; ud2 user0 ; +; jb #trap=user0 ; movq %rbp, %rsp ; popq %rbp ; ret @@ -179,9 +179,9 @@ block0(v0: i64, v1: i64): ; block1: ; offset 0x4 ; movq %rdi, %rax ; addq %rsi, %rax -; jae 0x12 -; ud2 ; trap: user0 +; jb 0x15 ; movq %rbp, %rsp ; popq %rbp ; retq +; ud2 ; trap: user0 diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat index 3010a8185f..9ce5548adf 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat @@ -48,7 +48,7 @@ ;; movl %edi, %r8d ;; movq %r8, %r11 ;; addq %r11, const(0), %r11 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rdi ;; cmpq %rdi, %r11 ;; jnbe label3; j label1 @@ -73,7 +73,7 @@ ;; movl %edi, %r8d ;; movq %r8, %r11 ;; addq %r11, const(0), %r11 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rdi ;; cmpq %rdi, %r11 ;; jnbe label3; j label1 diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat index 5c3c1ac1e2..748434c5de 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat @@ -48,7 +48,7 @@ ;; movl %edi, %r8d ;; movq %r8, %r11 ;; addq %r11, const(0), %r11 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rdi ;; cmpq %rdi, %r11 ;; jnbe label3; j label1 @@ -73,7 +73,7 @@ ;; movl %edi, %r8d ;; movq %r8, %r11 ;; addq %r11, const(0), %r11 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rdi ;; cmpq %rdi, %r11 ;; jnbe label3; j label1 diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index 412b479193..0cdce01dcf 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -48,7 +48,7 @@ ;; movl %edi, %r11d ;; movq %r11, %rax ;; addq %rax, const(0), %rax -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rcx ;; addq %r11, 0(%rdx), %r11 ;; movl $-65536, %edx @@ -72,7 +72,7 @@ ;; movl %edi, %r11d ;; movq %r11, %rax ;; addq %rax, const(0), %rax -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rcx ;; addq %r11, 0(%rsi), %r11 ;; movl $-65536, %edx diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index a4adf26635..4dad324de2 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i32_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -48,7 +48,7 @@ ;; movl %edi, %r11d ;; movq %r11, %rax ;; addq %rax, const(0), %rax -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rcx ;; addq %r11, 0(%rdx), %r11 ;; movl $-65536, %edx @@ -72,7 +72,7 @@ ;; movl %edi, %r11d ;; movq %r11, %rax ;; addq %rax, const(0), %rax -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rcx ;; addq %r11, 0(%rsi), %r11 ;; movl $-65536, %edx diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat index 277b469a81..f1e8d03c1f 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i32_access_0xffff0000_offset.wat @@ -47,7 +47,7 @@ ;; block0: ;; movq %rdi, %r10 ;; addq %r10, const(0), %r10 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %r11 ;; cmpq %r11, %r10 ;; jnbe label3; j label1 @@ -71,7 +71,7 @@ ;; block0: ;; movq %rdi, %r10 ;; addq %r10, const(0), %r10 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %r11 ;; cmpq %r11, %r10 ;; jnbe label3; j label1 diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat index a790538c98..a9a609a079 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_no_spectre_i8_access_0xffff0000_offset.wat @@ -47,7 +47,7 @@ ;; block0: ;; movq %rdi, %r10 ;; addq %r10, const(0), %r10 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %r11 ;; cmpq %r11, %r10 ;; jnbe label3; j label1 @@ -71,7 +71,7 @@ ;; block0: ;; movq %rdi, %r10 ;; addq %r10, const(0), %r10 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %r11 ;; cmpq %r11, %r10 ;; jnbe label3; j label1 diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat index 369f5146af..3d3c0ad94b 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i32_access_0xffff0000_offset.wat @@ -47,7 +47,7 @@ ;; block0: ;; movq %rdi, %r8 ;; addq %r8, const(0), %r8 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rax ;; movq %rdi, %rcx ;; addq %rcx, 0(%rdx), %rcx @@ -71,7 +71,7 @@ ;; block0: ;; movq %rdi, %rdx ;; addq %rdx, const(0), %rdx -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rax ;; movq %rdi, %rcx ;; addq %rcx, 0(%rsi), %rcx diff --git a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat index e3aa79c864..aad9fe06b0 100644 --- a/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat +++ b/cranelift/filetests/filetests/isa/x64/wasm/load_store_dynamic_kind_i64_index_0_guard_yes_spectre_i8_access_0xffff0000_offset.wat @@ -47,7 +47,7 @@ ;; block0: ;; movq %rdi, %r8 ;; addq %r8, const(0), %r8 -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rdx), %rax ;; movq %rdi, %rcx ;; addq %rcx, 0(%rdx), %rcx @@ -71,7 +71,7 @@ ;; block0: ;; movq %rdi, %rdx ;; addq %rdx, const(0), %rdx -;; jnb ; ud2 heap_oob ; +;; jb #trap=heap_oob ;; movq 8(%rsi), %rax ;; movq %rdi, %rcx ;; addq %rcx, 0(%rsi), %rcx diff --git a/tests/all/traps.rs b/tests/all/traps.rs index e6785979af..77dcf38654 100644 --- a/tests/all/traps.rs +++ b/tests/all/traps.rs @@ -641,10 +641,15 @@ fn assert_trap_code(wat: &str, code: wasmtime::Trap) { }; let trap = err.downcast_ref::().unwrap(); assert_eq!(*trap, code); + + let trace = err.downcast_ref::().unwrap().frames(); + assert!(trace.len() > 0); + assert_eq!(trace[0].func_index(), 0); + assert!(trace[0].func_offset().is_some()); } #[test] -fn heap_out_of_bounds_trap() { +fn trap_codes() { assert_trap_code( r#" (module @@ -666,6 +671,46 @@ fn heap_out_of_bounds_trap() { "#, Trap::MemoryOutOfBounds, ); + + for (ty, min) in [("i32", i32::MIN as u32 as u64), ("i64", i64::MIN as u64)] { + for op in ["rem", "div"] { + for sign in ["u", "s"] { + println!("testing {ty}.{op}_{sign}"); + assert_trap_code( + &format!( + r#" + (module + (func $div (param {ty} {ty}) (result {ty}) + local.get 0 + local.get 1 + {ty}.{op}_{sign}) + (func $start (drop (call $div ({ty}.const 1) ({ty}.const 0)))) + (start $start) + ) + "# + ), + Trap::IntegerDivisionByZero, + ); + } + } + + println!("testing {ty}.div_s INT_MIN/-1"); + assert_trap_code( + &format!( + r#" + (module + (func $div (param {ty} {ty}) (result {ty}) + local.get 0 + local.get 1 + {ty}.div_s) + (func $start (drop (call $div ({ty}.const {min}) ({ty}.const -1)))) + (start $start) + ) + "# + ), + Trap::IntegerOverflow, + ); + } } fn rustc(src: &str) -> Vec { diff --git a/winch/filetests/filetests/x64/i32_divs/const.wat b/winch/filetests/filetests/x64/i32_divs/const.wat index cd9be27f2d..541d0314ce 100644 --- a/winch/filetests/filetests/x64/i32_divs/const.wat +++ b/winch/filetests/filetests/x64/i32_divs/const.wat @@ -12,9 +12,9 @@ ;; 4: b90a000000 mov ecx, 0xa ;; 9: b814000000 mov eax, 0x14 ;; e: 83f900 cmp ecx, 0 -;; 11: 0f8502000000 jne 0x19 -;; 17: 0f0b ud2 -;; 19: 99 cdq -;; 1a: f7f9 idiv ecx -;; 1c: 5d pop rbp -;; 1d: c3 ret +;; 11: 0f8405000000 je 0x1c +;; 17: 99 cdq +;; 18: f7f9 idiv ecx +;; 1a: 5d pop rbp +;; 1b: c3 ret +;; 1c: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i32_divs/one_zero.wat b/winch/filetests/filetests/x64/i32_divs/one_zero.wat index 6b3094ea65..3ece4e316c 100644 --- a/winch/filetests/filetests/x64/i32_divs/one_zero.wat +++ b/winch/filetests/filetests/x64/i32_divs/one_zero.wat @@ -12,9 +12,9 @@ ;; 4: b900000000 mov ecx, 0 ;; 9: b801000000 mov eax, 1 ;; e: 83f900 cmp ecx, 0 -;; 11: 0f8502000000 jne 0x19 -;; 17: 0f0b ud2 -;; 19: 99 cdq -;; 1a: f7f9 idiv ecx -;; 1c: 5d pop rbp -;; 1d: c3 ret +;; 11: 0f8405000000 je 0x1c +;; 17: 99 cdq +;; 18: f7f9 idiv ecx +;; 1a: 5d pop rbp +;; 1b: c3 ret +;; 1c: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i32_divs/overflow.wat b/winch/filetests/filetests/x64/i32_divs/overflow.wat index 33c7d05bb9..0d4fa98b43 100644 --- a/winch/filetests/filetests/x64/i32_divs/overflow.wat +++ b/winch/filetests/filetests/x64/i32_divs/overflow.wat @@ -12,9 +12,9 @@ ;; 4: b9ffffffff mov ecx, 0xffffffff ;; 9: b800000080 mov eax, 0x80000000 ;; e: 83f900 cmp ecx, 0 -;; 11: 0f8502000000 jne 0x19 -;; 17: 0f0b ud2 -;; 19: 99 cdq -;; 1a: f7f9 idiv ecx -;; 1c: 5d pop rbp -;; 1d: c3 ret +;; 11: 0f8405000000 je 0x1c +;; 17: 99 cdq +;; 18: f7f9 idiv ecx +;; 1a: 5d pop rbp +;; 1b: c3 ret +;; 1c: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i32_divs/params.wat b/winch/filetests/filetests/x64/i32_divs/params.wat index cc3c25b8c1..31667f172a 100644 --- a/winch/filetests/filetests/x64/i32_divs/params.wat +++ b/winch/filetests/filetests/x64/i32_divs/params.wat @@ -15,10 +15,10 @@ ;; f: 8b0c24 mov ecx, dword ptr [rsp] ;; 12: 8b442404 mov eax, dword ptr [rsp + 4] ;; 16: 83f900 cmp ecx, 0 -;; 19: 0f8502000000 jne 0x21 -;; 1f: 0f0b ud2 -;; 21: 99 cdq -;; 22: f7f9 idiv ecx -;; 24: 4883c408 add rsp, 8 -;; 28: 5d pop rbp -;; 29: c3 ret +;; 19: 0f8409000000 je 0x28 +;; 1f: 99 cdq +;; 20: f7f9 idiv ecx +;; 22: 4883c408 add rsp, 8 +;; 26: 5d pop rbp +;; 27: c3 ret +;; 28: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i32_divs/zero_zero.wat b/winch/filetests/filetests/x64/i32_divs/zero_zero.wat index 7158174ad6..dd36dd8b2f 100644 --- a/winch/filetests/filetests/x64/i32_divs/zero_zero.wat +++ b/winch/filetests/filetests/x64/i32_divs/zero_zero.wat @@ -12,9 +12,9 @@ ;; 4: b900000000 mov ecx, 0 ;; 9: b800000000 mov eax, 0 ;; e: 83f900 cmp ecx, 0 -;; 11: 0f8502000000 jne 0x19 -;; 17: 0f0b ud2 -;; 19: 99 cdq -;; 1a: f7f9 idiv ecx -;; 1c: 5d pop rbp -;; 1d: c3 ret +;; 11: 0f8405000000 je 0x1c +;; 17: 99 cdq +;; 18: f7f9 idiv ecx +;; 1a: 5d pop rbp +;; 1b: c3 ret +;; 1c: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i64_divs/const.wat b/winch/filetests/filetests/x64/i64_divs/const.wat index 4f2d67cb27..18f51bb00f 100644 --- a/winch/filetests/filetests/x64/i64_divs/const.wat +++ b/winch/filetests/filetests/x64/i64_divs/const.wat @@ -12,9 +12,9 @@ ;; 4: 48c7c10a000000 mov rcx, 0xa ;; b: 48c7c014000000 mov rax, 0x14 ;; 12: 4883f900 cmp rcx, 0 -;; 16: 0f8502000000 jne 0x1e -;; 1c: 0f0b ud2 -;; 1e: 4899 cqo -;; 20: 48f7f9 idiv rcx -;; 23: 5d pop rbp -;; 24: c3 ret +;; 16: 0f8407000000 je 0x23 +;; 1c: 4899 cqo +;; 1e: 48f7f9 idiv rcx +;; 21: 5d pop rbp +;; 22: c3 ret +;; 23: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i64_divs/one_zero.wat b/winch/filetests/filetests/x64/i64_divs/one_zero.wat index 3c01564341..943b6da7df 100644 --- a/winch/filetests/filetests/x64/i64_divs/one_zero.wat +++ b/winch/filetests/filetests/x64/i64_divs/one_zero.wat @@ -12,9 +12,9 @@ ;; 4: 48c7c100000000 mov rcx, 0 ;; b: 48c7c001000000 mov rax, 1 ;; 12: 4883f900 cmp rcx, 0 -;; 16: 0f8502000000 jne 0x1e -;; 1c: 0f0b ud2 -;; 1e: 4899 cqo -;; 20: 48f7f9 idiv rcx -;; 23: 5d pop rbp -;; 24: c3 ret +;; 16: 0f8407000000 je 0x23 +;; 1c: 4899 cqo +;; 1e: 48f7f9 idiv rcx +;; 21: 5d pop rbp +;; 22: c3 ret +;; 23: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i64_divs/overflow.wat b/winch/filetests/filetests/x64/i64_divs/overflow.wat index 0161afa14a..3a7a0521f6 100644 --- a/winch/filetests/filetests/x64/i64_divs/overflow.wat +++ b/winch/filetests/filetests/x64/i64_divs/overflow.wat @@ -13,9 +13,9 @@ ;; b: 48b80000000000000080 ;; movabs rax, 0x8000000000000000 ;; 15: 4883f900 cmp rcx, 0 -;; 19: 0f8502000000 jne 0x21 -;; 1f: 0f0b ud2 -;; 21: 4899 cqo -;; 23: 48f7f9 idiv rcx -;; 26: 5d pop rbp -;; 27: c3 ret +;; 19: 0f8407000000 je 0x26 +;; 1f: 4899 cqo +;; 21: 48f7f9 idiv rcx +;; 24: 5d pop rbp +;; 25: c3 ret +;; 26: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i64_divs/params.wat b/winch/filetests/filetests/x64/i64_divs/params.wat index ee29c99b5e..2fdd6d8e09 100644 --- a/winch/filetests/filetests/x64/i64_divs/params.wat +++ b/winch/filetests/filetests/x64/i64_divs/params.wat @@ -15,10 +15,10 @@ ;; 11: 488b0c24 mov rcx, qword ptr [rsp] ;; 15: 488b442408 mov rax, qword ptr [rsp + 8] ;; 1a: 4883f900 cmp rcx, 0 -;; 1e: 0f8502000000 jne 0x26 -;; 24: 0f0b ud2 -;; 26: 4899 cqo -;; 28: 48f7f9 idiv rcx -;; 2b: 4883c410 add rsp, 0x10 -;; 2f: 5d pop rbp -;; 30: c3 ret +;; 1e: 0f840b000000 je 0x2f +;; 24: 4899 cqo +;; 26: 48f7f9 idiv rcx +;; 29: 4883c410 add rsp, 0x10 +;; 2d: 5d pop rbp +;; 2e: c3 ret +;; 2f: 0f0b ud2 diff --git a/winch/filetests/filetests/x64/i64_divs/zero_zero.wat b/winch/filetests/filetests/x64/i64_divs/zero_zero.wat index 8206994510..78b67bb20f 100644 --- a/winch/filetests/filetests/x64/i64_divs/zero_zero.wat +++ b/winch/filetests/filetests/x64/i64_divs/zero_zero.wat @@ -12,9 +12,9 @@ ;; 4: 48c7c100000000 mov rcx, 0 ;; b: 48c7c000000000 mov rax, 0 ;; 12: 4883f900 cmp rcx, 0 -;; 16: 0f8502000000 jne 0x1e -;; 1c: 0f0b ud2 -;; 1e: 4899 cqo -;; 20: 48f7f9 idiv rcx -;; 23: 5d pop rbp -;; 24: c3 ret +;; 16: 0f8407000000 je 0x23 +;; 1c: 4899 cqo +;; 1e: 48f7f9 idiv rcx +;; 21: 5d pop rbp +;; 22: c3 ret +;; 23: 0f0b ud2