Skip to content

Commit 5873ee5

Browse files
authored
Rollup merge of #128666 - pitaj:intrinsic-overflow_checks, r=BoxyUwU
Add `overflow_checks` intrinsic This adds an intrinsic which allows code in a pre-built library to inherit the overflow checks option from a crate depending on it. This enables code in the standard library to explicitly change behavior based on whether `overflow_checks` are enabled, regardless of the setting used when standard library was compiled. This is very similar to the `ub_checks` intrinsic, and refactors the two to use a common mechanism. The primary use case for this is to allow the new `RangeFrom` iterator to yield the maximum element before overflowing, as requested [here](rust-lang/rust#125687 (comment)). This PR includes a working `IterRangeFrom` implementation based on this new intrinsic that exhibits the desired behavior. [Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Ability.20to.20select.20code.20based.20on.20.60overflow_checks.60.3F)
2 parents a44af2b + 482feee commit 5873ee5

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/base.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,17 +865,8 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
865865
fields.iter(),
866866
)
867867
.bytes(),
868-
NullOp::UbChecks => {
869-
let val = fx.tcx.sess.ub_checks();
870-
let val = CValue::by_val(
871-
fx.bcx.ins().iconst(types::I8, i64::from(val)),
872-
fx.layout_of(fx.tcx.types.bool),
873-
);
874-
lval.write_cvalue(fx, val);
875-
return;
876-
}
877-
NullOp::ContractChecks => {
878-
let val = fx.tcx.sess.contract_checks();
868+
NullOp::RuntimeChecks(kind) => {
869+
let val = kind.value(fx.tcx.sess);
879870
let val = CValue::by_val(
880871
fx.bcx.ins().iconst(types::I8, i64::from(val)),
881872
fx.layout_of(fx.tcx.types.bool),

0 commit comments

Comments
 (0)