Skip to content

Commit 8c6c99a

Browse files
committed
builder: work around rust-lang/rust#101483 abusing implicit i1->i8 zext (from_immediate).
1 parent 7945f17 commit 8c6c99a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,21 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
11691169
ty
11701170
)),
11711171
};
1172+
1173+
// HACK(eddyb) https://github.com/rust-lang/rust/pull/101483 accidentally
1174+
// abused the fact that an `i1` LLVM value will be automatically `zext`'d
1175+
// to `i8` by `from_immediate`, and so you can pretend that, from the
1176+
// Rust perspective, a `bool` value has the type `u8`, as long as it will
1177+
// be stored to memory (which intrinsics all do, for historical reasons)
1178+
// - but we don't do that in `from_immediate`, so it's emulated here.
1179+
let val = match (self.lookup_type(val.ty), self.lookup_type(ptr_elem_ty)) {
1180+
(SpirvType::Bool, SpirvType::Integer(8, false)) => {
1181+
self.zext(val, ptr_elem_ty)
1182+
}
1183+
1184+
_ => val
1185+
};
1186+
11721187
assert_ty_eq!(self, ptr_elem_ty, val.ty);
11731188
self.emit()
11741189
.store(ptr.def(self), val.def(self), None, empty())

0 commit comments

Comments
 (0)