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 be924ef commit 55c584a
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 @@ -262,7 +262,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 @@ -597,6 +598,17 @@ where
}
}

/// 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)
}
}

/// Sign-extend the low `from_bits` bits of `value` to a full u64.
#[inline]
fn sign_extend_to_u64(value: u64, from_bits: u8) -> u64 {
Expand Down

0 comments on commit 55c584a

Please sign in to comment.