Conversation
With overflow checks on, rustc lowers `+`, `-` and `*` on integers to AddWithOverflow/SubWithOverflow/MulWithOverflow followed by an assertion on the overflow flag, and these fell through to unimplemented!. They now evaluate to the pair of the mathematical result and whether it lies outside the operand type's range, so the existing Assert handling turns each overflow check into a verification condition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MvvhC4sHsobSMHAn9CgLBq
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the first stage of the fix for the arithmetic-overflow issue found while reviewing #278.
With overflow checks on, rustc lowers integer
+/-/*toAddWithOverflow/SubWithOverflow/MulWithOverflowfollowed by anasserton the overflow flag. Thrust hitunimplemented!on these operations, which is why every UI test is compiled with-C debug-assertions=off.Changes
AddWithOverflow/SubWithOverflow/MulWithOverflownow evaluate to the pair(result, overflowed):resultis the mathematical result, with no wrapping. rustc reads it only after the assertion that no overflow happened, so it is always in range when read.overflowedis true exactly whenresultlies outside the operand type's range.Asserthandling then turns each overflow check into a verification condition, so a program that can overflow is rejected.Analyzer::local_decls.body.local_declsdoes not include the temporaries thatReborrowVisitoradds.Tests
Both pairs are compiled with
-C overflow-checks=on:int_overflow_checked: ani64x + 1guarded againsti64::MAX. The fail side has the guard off by one.int_underflow_checked: au32x - 1guarded against0. The fail side has the guard off by one.On
main, both pairs stop atnot implemented: ty=int, op=AddWithOverflow(orSubWithOverflow).cargo testfails on exactly the same set of tests asmain(65 PCSat tests: the localcoar:mainimage can't handle(Seq Int)). fmt and clippy are clean.Not covered (next stage)
u32parameter is non-negative, so a guard is needed on both sides of a value unless the inferred precondition already bounds it.🤖 Generated with Claude Code
https://claude.ai/code/session_01MvvhC4sHsobSMHAn9CgLBq
Generated by Claude Code