Skip to content

Commit

Permalink
Insert null checks for pointer dereferences when debug assertions are…
Browse files Browse the repository at this point in the history
… enabled

Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: rust-lang/rust-project-goals#177.
  • Loading branch information
1c3t3a committed Jan 31, 2025
1 parent 7b19e13 commit 77f3081
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
Some(source_info.span),
);
}
AssertKind::NullPointerDereference => {
let location = fx.get_caller_location(source_info).load_scalar(fx);

codegen_panic_inner(
fx,
rustc_hir::LangItem::PanicNullPointerDereference,
&[location],
Some(source_info.span),
)
}
_ => {
let location = fx.get_caller_location(source_info).load_scalar(fx);

Expand Down

0 comments on commit 77f3081

Please sign in to comment.