transpile: Cast overflow builtin operands to the output type#1863
Merged
Conversation
Contributor
|
@thedataking I don't think there is any overlap between the two PRs, since this one deals with the parameter types and not the actual result type of the function. |
ahomescu
reviewed
Jun 19, 2026
7fc752f to
b8781e0
Compare
b8781e0 to
bce177f
Compare
47dd51b to
78b9790
Compare
78b9790 to
01da5b4
Compare
The type-generic __builtin_{add,sub,mul}_overflow accept operand and
result types that all differ, without arithmetic conversions. The
previous translation applied Rust's overflowing_* directly to the
operands, which does not compile when their Rust types differ and does
not account for a narrower result type.
When all three types translate to one Rust type, keep using the native
overflowing_* method. Otherwise, compute in i128 (overflow is defined
against the infinite-precision result) and derive the overflow flag
from the i128 overflow together with a narrowing roundtrip check.
Snapshot tests run with fail_on_error, so a decl that fails translation aborts the test. Add an expect_translation_error knob that turns fail_on_error off; failed decls are then omitted from the output, so the snapshot records which decls are rejected.
The i128 used to compute the infinite-precision result cannot represent all values of unsigned __int128 operands or results, which would silently corrupt the overflow flag. Same-type 128-bit uses keep mapping to Rust's native overflowing_* methods. See #1878.
01da5b4 to
5b44f57
Compare
ahomescu
approved these changes
Jul 1, 2026
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.
The type-generic
__builtin_{add,sub,mul}_overflowaccept operand and result types that all differ, which the previous translation did not handle. When all three types translate to one Rust type, keep mapping to the nativeoverflowing_*methods; otherwise compute ini128and derive the overflow flag from a narrowing roundtrip check. Mixed-type uses involving 128-bit integers are rejected rather than translated wrongly (#1878); a new snapshot-test knob pins which decls are rejected.Covers the overflow-builtin uses in libgit2 (#1861), which are all ≤64-bit integer types.
Possibly superseded by the broader builtin type-handling rework in #1860 / #1707.Tagging @Rua for coordination.