From 410893e9a93920c893e8a63c695bd08d7c801838 Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Wed, 14 Mar 2018 20:48:28 +0100 Subject: [PATCH] [Liftoff][x64] Assert that 32-bit values are zero extended On x64, the upper 32 bit of a register holding a 32-bit value are always zero. Add several assertions to check that. This is particularly important for memory accesses, where the whole 64-bit register is used as offset for the memory access. R=titzer@chromium.org Bug: v8:6600 Change-Id: Ifd3c6e90bb0056dbc2b8c66de919f35c7787965b Reviewed-on: https://chromium-review.googlesource.com/963321 Commit-Queue: Clemens Hammacher Reviewed-by: Ben Titzer Cr-Commit-Position: refs/heads/master@{#51947} --- src/wasm/baseline/x64/liftoff-assembler-x64.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wasm/baseline/x64/liftoff-assembler-x64.h b/src/wasm/baseline/x64/liftoff-assembler-x64.h index d065ce4f5f..d0605fa782 100644 --- a/src/wasm/baseline/x64/liftoff-assembler-x64.h +++ b/src/wasm/baseline/x64/liftoff-assembler-x64.h @@ -160,6 +160,9 @@ void LiftoffAssembler::Load(LiftoffRegister dst, Register src_addr, Register offset_reg, uint32_t offset_imm, LoadType type, LiftoffRegList pinned, uint32_t* protected_load_pc) { + if (emit_debug_code() && offset_reg != no_reg) { + AssertZeroExtended(offset_reg); + } Operand src_op = liftoff::GetMemOp(this, src_addr, offset_reg, offset_imm, pinned); if (protected_load_pc) *protected_load_pc = pc_offset(); @@ -209,6 +212,9 @@ void LiftoffAssembler::Store(Register dst_addr, Register offset_reg, uint32_t offset_imm, LiftoffRegister src, StoreType type, LiftoffRegList pinned, uint32_t* protected_store_pc) { + if (emit_debug_code() && offset_reg != no_reg) { + AssertZeroExtended(offset_reg); + } Operand dst_op = liftoff::GetMemOp(this, dst_addr, offset_reg, offset_imm, pinned); if (protected_store_pc) *protected_store_pc = pc_offset(); @@ -653,8 +659,8 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, movsxlq(dst.gp(), src.gp()); return true; case kExprI64UConvertI32: + AssertZeroExtended(src.gp()); if (dst.gp() != src.gp()) movl(dst.gp(), src.gp()); - // TODO(clemensh): Add assertion that the upper 32 bit are zero. return true; case kExprI64ReinterpretF64: Movq(dst.gp(), src.fp());