diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index aa01668dfa..954599fb1d 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -193,7 +193,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match *ty { SpirvType::Void => self.fatal("memset invalid on void pattern"), SpirvType::Bool => self.fatal("memset invalid on bool pattern"), - SpirvType::Integer(width, _signedness) => match width { + SpirvType::Integer(width, false) => match width { 8 => self.constant_u8(self.span(), fill_byte).def(self), 16 => self .constant_u16(self.span(), memset_fill_u16(fill_byte)) @@ -208,6 +208,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { "memset on integer width {width} not implemented yet" )), }, + SpirvType::Integer(width, true) => match width { + 8 => self + .constant_i8(self.span(), unsafe { + std::mem::transmute::(fill_byte) + }) + .def(self), + 16 => self + .constant_i16(self.span(), unsafe { + std::mem::transmute::(memset_fill_u16(fill_byte)) + }) + .def(self), + 32 => self + .constant_i32(self.span(), unsafe { + std::mem::transmute::(memset_fill_u32(fill_byte)) + }) + .def(self), + 64 => self + .constant_i64(self.span(), unsafe { + std::mem::transmute::(memset_fill_u64(fill_byte)) + }) + .def(self), + _ => self.fatal(format!( + "memset on integer width {width} not implemented yet" + )), + }, SpirvType::Float(width) => match width { 32 => self .constant_f32(self.span(), f32::from_bits(memset_fill_u32(fill_byte))) @@ -318,7 +343,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } else { for index in 0..count { let const_index = self.constant_u32(self.span(), index as u32); - let gep_ptr = self.gep(pat.ty, ptr, &[const_index]); + let gep_ptr = self.inbounds_gep(pat.ty, ptr, &[const_index]); self.store(pat, gep_ptr, Align::from_bytes(0).unwrap()); } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index a53e1e0de6..07e617c898 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -42,6 +42,10 @@ impl<'tcx> CodegenCx<'tcx> { self.constant_int_from_native_unsigned(span, val) } + pub fn constant_i64(&self, span: Span, val: i64) -> SpirvValue { + self.constant_int_from_native_signed(span, val) + } + pub fn constant_u64(&self, span: Span, val: u64) -> SpirvValue { self.constant_int_from_native_unsigned(span, val) } diff --git a/tests/ui/lang/core/array/init_array_i16.rs b/tests/ui/lang/core/array/init_array_i16.rs new file mode 100644 index 0000000000..d0f3269e0c --- /dev/null +++ b/tests/ui/lang/core/array/init_array_i16.rs @@ -0,0 +1,10 @@ +// Test creating an array. +// build-pass + +use spirv_std::macros::spirv; + +#[spirv(fragment)] +pub fn main(o: &mut i16) { + let array = [0i16; 4]; + *o = array[1]; +} diff --git a/tests/ui/lang/core/array/init_array_i32.rs b/tests/ui/lang/core/array/init_array_i32.rs new file mode 100644 index 0000000000..c6fea6b900 --- /dev/null +++ b/tests/ui/lang/core/array/init_array_i32.rs @@ -0,0 +1,10 @@ +// Test creating an array. +// build-pass + +use spirv_std::macros::spirv; + +#[spirv(fragment)] +pub fn main(o: &mut i32) { + let array = [0i32; 4]; + *o = array[1]; +} diff --git a/tests/ui/lang/core/array/init_array_i64.rs b/tests/ui/lang/core/array/init_array_i64.rs new file mode 100644 index 0000000000..8f5120c27c --- /dev/null +++ b/tests/ui/lang/core/array/init_array_i64.rs @@ -0,0 +1,10 @@ +// Test creating an array. +// build-pass + +use spirv_std::macros::spirv; + +#[spirv(fragment)] +pub fn main(o: &mut i64) { + let array = [0i64; 4]; + *o = array[1]; +} diff --git a/tests/ui/lang/core/array/init_array_i8.rs b/tests/ui/lang/core/array/init_array_i8.rs new file mode 100644 index 0000000000..fda9b1abcd --- /dev/null +++ b/tests/ui/lang/core/array/init_array_i8.rs @@ -0,0 +1,10 @@ +// Test creating an array. +// build-pass + +use spirv_std::macros::spirv; + +#[spirv(fragment)] +pub fn main(o: &mut i8) { + let array = [0i8; 4]; + *o = array[1]; +}