Repository navigation
Conversation
DORA-B
marked this pull request as ready for review
September 25, 2026 03:58
DORA-B
force-pushed
the
fix/arm-a-profile-divzero
branch
from
November 21, 2026 03:19
2728d48 to
78d4109
Compare
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.
Summary
Arm integer division by zero has a defined zero result in the A-profile
execution environments covered here. The A32, Thumb-2, and AArch64 frontends
currently pass a zero divisor directly to generic VEX division operations.
Consequently, an IR consumer can raise a division exception instead of
returning the required result.
This change handles the zero divisor in the frontend: divide by a safe
nonzero operand internally, then select zero as the architectural result.
It covers
SDIVandUDIVin A32 and Thumb-2, and both W/X forms in AArch64.Architectural definition
Direct instruction references are available in the following third-party
HTML mirrors of Arm's instruction descriptions (not Arm-hosted pages):
and UDIV
(Arm release 2026-03).
and UDIV
(Arm pseudocode release 2023-06; each page includes A32 and T32 encodings).
All four pages' Operation sections explicitly select zero when the divisor is
zero. These links were checked against the instruction contents, rather than
only the destination URL.
For a zero divisor, the required quotient is zero. This is an instruction-level
rule, not the undefined behavior of division by zero in C or C++.
Arm's explanation of profile-specific division behavior
also explicitly distinguishes A-profile's zero result from the configurable
trapping behavior in R/M profiles. This patch does not add support for
SCTLR.DZorCCR.DIV_0_TRP, and must not be read as implementing thosesystem-level trapping configurations. Integer division does not update the
condition flags; existing conditional destination writes are preserved.
Root cause
The frontends lower these instructions directly to
Iop_DivS32,Iop_DivU32,Iop_DivS64, orIop_DivU64. Those generic operations do not encode Arm'sspecial zero-divisor result. PyVEX's
ZeroDivisionPostProcessorcan insert anIjk_SigFPE_IntDivexit for that operand, and angr then reportsSimZeroDivisionException.Selecting zero only after an unsafe division is insufficient: the division
itself must also receive a nonzero divisor.
Reproduction
Expected:
sdiv 0andudiv 0. Without the fix, both raise a divide-by-zeroexception. The patch must be used through a PyVEX build containing the changed
VEX frontends.
Fix
For each affected instruction, construct the following operations at its
operand width:
For a zero divisor, the internal division receives one and the selected result
is zero. For a nonzero divisor, the original operands and division operation
are retained. The generic divide-by-zero guard remains intact, but its operand
is provably nonzero. Existing destination-width handling and conditional
register writes are unchanged.
Relation to the RISC-V fix
My related RISC-V division fix, PR #84,
addresses the same mismatch between generic division behavior and a guest
architecture's defined exceptional results. It is a related implementation,
not a dependency or a substitute for the Arm specification.
The results intentionally differ:
SDIV/UDIVin the scope aboveDIV/DIVUREM/REMUThe RISC-V values are specified in the M-extension division definition.
Both changes use a safe internal divisor and then select the result required
by their respective architecture. Neither removes divide exceptions globally
or changes the rules for architectures that require trapping.
The RISC-V PR additionally guards signed overflow (
INT_MIN / -1). This Armpatch is specifically a divide-by-zero repair: it leaves nonzero-divisor
lowering unchanged and does not claim to resolve generic VEX signed-overflow
semantics. That case requires a separate explicit guard to establish the same
backend-independent guarantee.