detect incorrect vtable alignment during const eval instead of ICE-ing
also add tests for these 2 kinds of errors for size and alignment, as the existing size check wasn't apparently tested
This commit is contained in:
parent
47d38752c6
commit
d44990367d
3 changed files with 51 additions and 1 deletions
|
@ -158,6 +158,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let size = u64::try_from(self.force_bits(size, pointer_size)?).unwrap();
|
||||
let align = vtable.read_ptr_sized(pointer_size * 2)?.check_init()?;
|
||||
let align = u64::try_from(self.force_bits(align, pointer_size)?).unwrap();
|
||||
let align = Align::from_bytes(align)
|
||||
.map_err(|e| err_ub_format!("invalid vtable: alignment {}", e))?;
|
||||
|
||||
if size >= self.tcx.data_layout.obj_size_bound() {
|
||||
throw_ub_format!(
|
||||
|
@ -165,6 +167,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
size is bigger than largest supported object"
|
||||
);
|
||||
}
|
||||
Ok((Size::from_bytes(size), Align::from_bytes(align).unwrap()))
|
||||
Ok((Size::from_bytes(size), align))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue