Insert null checks for pointer dereferences when debug assertions are 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: https://github.com/rust-lang/rust-project-goals/pull/177.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user