Skip to content

Commit 7c0948f

Browse files
authored
Merge pull request #3102 from afonso360/fix-bool-trampolines
cranelift: Fix trampoline args for b1 types
2 parents e9f33fc + 8862499 commit 7c0948f

File tree

3 files changed

+19
-46
lines changed

3 files changed

+19
-46
lines changed

cranelift/codegen/src/data_value.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ impl DataValue {
6666
}
6767
}
6868

69+
/// Return true if the value is a bool (i.e. `DataValue::B`).
70+
pub fn is_bool(&self) -> bool {
71+
match self {
72+
DataValue::B(_) => true,
73+
_ => false,
74+
}
75+
}
76+
6977
/// Write a [DataValue] to a memory location.
7078
pub unsafe fn write_value_to(&self, p: *mut u128) {
7179
match self {
72-
DataValue::B(b) => ptr::write(p as *mut bool, *b),
80+
DataValue::B(b) => ptr::write(p, if *b { -1i128 as u128 } else { 0u128 }),
7381
DataValue::I8(i) => ptr::write(p as *mut i8, *i),
7482
DataValue::I16(i) => ptr::write(p as *mut i16, *i),
7583
DataValue::I32(i) => ptr::write(p as *mut i32, *i),
@@ -90,7 +98,7 @@ impl DataValue {
9098
types::I64 => DataValue::I64(ptr::read(p as *const i64)),
9199
types::F32 => DataValue::F32(ptr::read(p as *const Ieee32)),
92100
types::F64 => DataValue::F64(ptr::read(p as *const Ieee64)),
93-
_ if ty.is_bool() => DataValue::B(ptr::read(p as *const bool)),
101+
_ if ty.is_bool() => DataValue::B(ptr::read(p) != 0),
94102
_ if ty.is_vector() && ty.bytes() == 16 => {
95103
DataValue::V128(ptr::read(p as *const [u8; 16]))
96104
}

cranelift/filetests/filetests/runtests/br.clif

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,8 @@ block2:
9090
; run: %brz_i8(-1) == false
9191

9292

93-
; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
94-
function %brz_b1_true() -> b1 {
95-
block0:
96-
v1 = bconst.b1 true
97-
brz v1, block1
98-
jump block2
99-
100-
block1:
101-
v2 = bconst.b1 true
102-
return v2
103-
104-
block2:
105-
v3 = bconst.b1 false
106-
return v3
107-
}
108-
; run: %brz_b1_true() == false
109-
110-
function %brz_b1_false() -> b1 {
111-
block0:
112-
v1 = bconst.b1 false
93+
function %brz_b1(b1) -> b1 {
94+
block0(v1: b1):
11395
brz v1, block1
11496
jump block2
11597

@@ -121,8 +103,8 @@ block2:
121103
v3 = bconst.b1 false
122104
return v3
123105
}
124-
; run: %brz_b1_false() == true
125-
106+
; run: %brz_b1(true) == false
107+
; run: %brz_b1(false) == true
126108

127109

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

196178

197-
; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
198-
function %brnz_b1_true() -> b1 {
199-
block0:
200-
v1 = bconst.b1 true
201-
brnz v1, block1
202-
jump block2
203-
204-
block1:
205-
v2 = bconst.b1 true
206-
return v2
207-
208-
block2:
209-
v3 = bconst.b1 false
210-
return v3
211-
}
212-
; run: %brnz_b1_true() == true
213-
214-
function %brnz_b1_false() -> b1 {
215-
block0:
216-
v1 = bconst.b1 false
179+
function %brnz_b1(b1) -> b1 {
180+
block0(v1: b1):
217181
brnz v1, block1
218182
jump block2
219183

@@ -225,4 +189,5 @@ block2:
225189
v3 = bconst.b1 false
226190
return v3
227191
}
228-
; run: %brnz_b1_false() == false
192+
; run: %brnz_b1(true) == true
193+
; run: %brnz_b1(false) == false

cranelift/filetests/src/function_runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl UnboxedValues {
198198
// Store the argument values into `values_vec`.
199199
for ((arg, slot), param) in arguments.iter().zip(&mut values_vec).zip(&signature.params) {
200200
assert!(
201-
arg.ty() == param.value_type || arg.is_vector(),
201+
arg.ty() == param.value_type || arg.is_vector() || arg.is_bool(),
202202
"argument type mismatch: {} != {}",
203203
arg.ty(),
204204
param.value_type

0 commit comments

Comments
 (0)