Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift: Fix trampoline args for b1 types #3102

Merged
merged 1 commit into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cranelift/codegen/src/data_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ impl DataValue {
}
}

/// Return true if the value is a bool (i.e. `DataValue::B`).
pub fn is_bool(&self) -> bool {
match self {
DataValue::B(_) => true,
_ => false,
}
}

/// Write a [DataValue] to a memory location.
pub unsafe fn write_value_to(&self, p: *mut u128) {
match self {
DataValue::B(b) => ptr::write(p as *mut bool, *b),
DataValue::B(b) => ptr::write(p, if *b { -1i128 as u128 } else { 0u128 }),
DataValue::I8(i) => ptr::write(p as *mut i8, *i),
DataValue::I16(i) => ptr::write(p as *mut i16, *i),
DataValue::I32(i) => ptr::write(p as *mut i32, *i),
Expand All @@ -86,7 +94,7 @@ impl DataValue {
types::I64 => DataValue::I64(ptr::read(p as *const i64)),
types::F32 => DataValue::F32(ptr::read(p as *const Ieee32)),
types::F64 => DataValue::F64(ptr::read(p as *const Ieee64)),
_ if ty.is_bool() => DataValue::B(ptr::read(p as *const bool)),
_ if ty.is_bool() => DataValue::B(ptr::read(p) != 0),
_ if ty.is_vector() && ty.bytes() == 16 => {
DataValue::V128(ptr::read(p as *const [u8; 16]))
}
Expand Down
51 changes: 8 additions & 43 deletions cranelift/filetests/filetests/runtests/br.clif
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,8 @@ block2:
; run: %brz_i8(-1) == false


; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
function %brz_b1_true() -> b1 {
block0:
v1 = bconst.b1 true
brz v1, block1
jump block2

block1:
v2 = bconst.b1 true
return v2

block2:
v3 = bconst.b1 false
return v3
}
; run: %brz_b1_true() == false

function %brz_b1_false() -> b1 {
block0:
v1 = bconst.b1 false
function %brz_b1(b1) -> b1 {
block0(v1: b1):
brz v1, block1
jump block2

Expand All @@ -121,8 +103,8 @@ block2:
v3 = bconst.b1 false
return v3
}
; run: %brz_b1_false() == true

; run: %brz_b1(true) == false
; run: %brz_b1(false) == true


function %brnz_i64(i64) -> b1 {
Expand Down Expand Up @@ -194,26 +176,8 @@ block2:
; run: %brnz_i8(-1) == true


; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
function %brnz_b1_true() -> b1 {
block0:
v1 = bconst.b1 true
brnz v1, block1
jump block2

block1:
v2 = bconst.b1 true
return v2

block2:
v3 = bconst.b1 false
return v3
}
; run: %brnz_b1_true() == true

function %brnz_b1_false() -> b1 {
block0:
v1 = bconst.b1 false
function %brnz_b1(b1) -> b1 {
block0(v1: b1):
brnz v1, block1
jump block2

Expand All @@ -225,4 +189,5 @@ block2:
v3 = bconst.b1 false
return v3
}
; run: %brnz_b1_false() == false
; run: %brnz_b1(true) == true
; run: %brnz_b1(false) == false
2 changes: 1 addition & 1 deletion cranelift/filetests/src/function_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl UnboxedValues {
// Store the argument values into `values_vec`.
for ((arg, slot), param) in arguments.iter().zip(&mut values_vec).zip(&signature.params) {
assert!(
arg.ty() == param.value_type || arg.is_vector(),
arg.ty() == param.value_type || arg.is_vector() || arg.is_bool(),
"argument type mismatch: {} != {}",
arg.ty(),
param.value_type
Expand Down