Skip to content

Commit e2e598f

Browse files
committed
Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obk
Insert alignment checks for pointer dereferences when debug assertions are enabled Closes rust-lang/rust#54915 - [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit) - [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue! - [x] Implement a more helpful panic message like slice bounds checking. r? `@oli-obk`
2 parents 69b57c2 + 8b18860 commit e2e598f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/base.rs

+12
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
379379
source_info.span,
380380
);
381381
}
382+
AssertKind::MisalignedPointerDereference { ref required, ref found } => {
383+
let required = codegen_operand(fx, required).load_scalar(fx);
384+
let found = codegen_operand(fx, found).load_scalar(fx);
385+
let location = fx.get_caller_location(source_info).load_scalar(fx);
386+
387+
codegen_panic_inner(
388+
fx,
389+
rustc_hir::LangItem::PanicBoundsCheck,
390+
&[required, found, location],
391+
source_info.span,
392+
);
393+
}
382394
_ => {
383395
let msg_str = msg.description();
384396
codegen_panic(fx, msg_str, source_info);

0 commit comments

Comments
 (0)