Skip to content

Commit 3d2869c

Browse files
committed
PR Feedback: Don't put SSA-only types in CValues
1 parent 039a3ba commit 3d2869c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,14 +1132,15 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
11321132
let is_eq_value =
11331133
if size == Size::ZERO {
11341134
// No bytes means they're trivially equal
1135-
fx.bcx.ins().bconst(types::B1, true)
1135+
fx.bcx.ins().iconst(types::I8, 1)
11361136
} else if let Some(clty) = type_by_size(size) {
11371137
// Can't use `trusted` for these loads; they could be unaligned.
11381138
let mut flags = MemFlags::new();
11391139
flags.set_notrap();
11401140
let lhs_val = fx.bcx.ins().load(clty, flags, lhs_ref, 0);
11411141
let rhs_val = fx.bcx.ins().load(clty, flags, rhs_ref, 0);
1142-
fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val)
1142+
let eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val);
1143+
fx.bcx.ins().bint(types::I8, eq)
11431144
} else {
11441145
// Just call `memcmp` (like slices do in core) when the
11451146
// size is too large or it's not a power-of-two.
@@ -1150,7 +1151,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
11501151
let returns = vec![AbiParam::new(types::I32)];
11511152
let args = &[lhs_ref, rhs_ref, bytes_val];
11521153
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
1153-
fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0)
1154+
let eq = fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0);
1155+
fx.bcx.ins().bint(types::I8, eq)
11541156
};
11551157
ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
11561158
};

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,6 @@ impl<'tcx> CPlace<'tcx> {
437437
| (types::F32, types::I32)
438438
| (types::I64, types::F64)
439439
| (types::F64, types::I64) => fx.bcx.ins().bitcast(dst_ty, data),
440-
441-
// Widen an abstract SSA boolean to something that can be stored in memory
442-
(types::B1, types::I8 | types::I16 | types::I32 | types::I64 | types::I128) => {
443-
fx.bcx.ins().bint(dst_ty, data)
444-
}
445-
446440
_ if src_ty.is_vector() && dst_ty.is_vector() => {
447441
fx.bcx.ins().raw_bitcast(dst_ty, data)
448442
}
@@ -459,6 +453,10 @@ impl<'tcx> CPlace<'tcx> {
459453
ptr.store(fx, data, MemFlags::trusted());
460454
ptr.load(fx, dst_ty, MemFlags::trusted())
461455
}
456+
457+
// `CValue`s should never contain SSA-only types, so if you ended
458+
// up here having seen an error like `B1 -> I8`, then before
459+
// calling `write_cvalue` you need to add a `bint` instruction.
462460
_ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
463461
};
464462
//fx.bcx.set_val_label(data, cranelift_codegen::ir::ValueLabel::new(var.index()));

0 commit comments

Comments
 (0)