Skip to content

Commit 2442d90

Browse files
oisyneddyb
authored andcommitted
Fix for read_scalar().unwrap() panicking
1 parent 69fb9e3 commit 2442d90

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,16 @@ impl<'tcx> CodegenCx<'tcx> {
456456
// only uses the input alloc_id in the case that the scalar is uninitilized
457457
// as part of the error output
458458
// tldr, the pointer here is only needed for the offset
459-
let scalar = alloc
460-
.inner()
461-
.read_scalar(self, alloc_range(*offset, size), primitive.is_ptr())
462-
.unwrap();
463-
let value = self.scalar_to_backend(scalar, self.primitive_to_scalar(primitive), ty);
464-
459+
let value = match alloc.inner().read_scalar(
460+
self,
461+
alloc_range(*offset, size),
462+
primitive.is_ptr(),
463+
) {
464+
Ok(scalar) => {
465+
self.scalar_to_backend(scalar, self.primitive_to_scalar(primitive), ty)
466+
}
467+
_ => self.undef(ty),
468+
};
465469
*offset += size;
466470
value
467471
}

0 commit comments

Comments
 (0)