fix(libc): wrap div, ldiv, lldiv and imaxdiv on a -1 divisor #16210
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16210"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-05T20:50:44Z.
What
div,ldiv,lldivandimaxdivwith a divisor of -1 and the most negative numerator (INT_MIN/INT64_MIN) divide with a quotient that does not fit the result type. C leaves that undefined, and the x86-64 hostidivfaults on it. Fix: a divisor of -1 returns the two's-complement negation of the numerator (computed unsigned, then cast) with a remainder of 0. This is what wrapping arithmetic gives and avoids the host trap.fixfordiv(Strings.cpp),fixforldiv/lldiv/imaxdiv(Math.cpp),testrows for each (GuestDivisionPrxAbi.cpp), and adocs(debt)entry indocs/dev/debt/libc.mdrecording that the console result forINT_MIN / -1andINT64_MIN / -1has not been measured.Tested
guest_division_prx_abi_testsis queued, not yet run.python3 tools/check_conventions.py --base upstream/main(passed),git diff --check upstream/main(clean).test_public_headers.py --audit-only) was run on this branch; no export declarations change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)