Skip to content

Commit

Permalink
builder: work around rust-lang/rust#101483 abusing implicit i1->i8 ze…
Browse files Browse the repository at this point in the history
…xt (from_immediate).
  • Loading branch information
eddyb committed Oct 28, 2022
1 parent d259e55 commit e71f0d2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,21 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
ty
)),
};

// HACK(eddyb) https://github.com/rust-lang/rust/pull/101483 accidentally
// abused the fact that an `i1` LLVM value will be automatically `zext`'d
// to `i8` by `from_immediate`, and so you can pretend that, from the
// Rust perspective, a `bool` value has the type `u8`, as long as it will
// be stored to memory (which intrinsics all do, for historical reasons)
// - but we don't do that in `from_immediate`, so it's emulated here.
let val = match (self.lookup_type(val.ty), self.lookup_type(ptr_elem_ty)) {
(SpirvType::Bool, SpirvType::Integer(8, false)) => {
self.zext(val, ptr_elem_ty)
}

_ => val
};

assert_ty_eq!(self, ptr_elem_ty, val.ty);
self.emit()
.store(ptr.def(self), val.def(self), None, empty())
Expand Down

0 comments on commit e71f0d2

Please sign in to comment.