Skip to content

Commit

Permalink
Fix a miscompile for s390x with constants
Browse files Browse the repository at this point in the history
This carries over a narrow fix from bytecodealliance#4427 to prior release branches. The
patch here was created by `@uweigand` during the investigation for bytecodealliance#4487.
  • Loading branch information
alexcrichton committed Jul 20, 2022
1 parent cf1c4fe commit 16d3744
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cranelift/codegen/src/isa/s390x/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ where
fn u64_from_value(&mut self, val: Value) -> Option<u64> {
let inst = self.lower_ctx.dfg().value_def(val).inst()?;
let constant = self.lower_ctx.get_constant(inst)?;
Some(constant)
let ty = self.lower_ctx.output_ty(inst, 0);
Some(zero_extend_to_u64(constant, self.ty_bits(ty).unwrap()))
}

#[inline]
Expand Down Expand Up @@ -516,3 +517,14 @@ where
self.lower_ctx.emit(inst.clone());
}
}

/// Zero-extend the low `from_bits` bits of `value` to a full u64.
#[inline]
fn zero_extend_to_u64(value: u64, from_bits: u8) -> u64 {
assert!(from_bits <= 64);
if from_bits >= 64 {
value
} else {
value & ((1u64 << from_bits) - 1)
}
}

0 comments on commit 16d3744

Please sign in to comment.