angr/tests/engines
Quintin Kong d46e56f891
Fix signed division and remainder in the pcode engine (#6739)
* Fix signed division and remainder in the pcode engine

OpBehaviorIntSdiv and OpBehaviorIntSrem used Claripy's `/` and `%`, which are
unsigned bit-vector operations. For negative operands they therefore produced
the same results as the unsigned INT_DIV and INT_REM behaviors.

INT_SDIV now uses claripy.SDiv (truncation toward zero). INT_SREM is defined as
in1 - SDiv(in1, in2) * in2, giving a remainder with the dividend's sign, which
matches the p-code semantics documented in the class comments.

For 64-bit -5 and 2, INT_SDIV now yields -2 (0xfffffffffffffffe) and INT_SREM
yields -1 (0xffffffffffffffff) instead of large unsigned values.

The arithmetic behavior test table enables both INT_SDIV and INT_SREM with the
matching signed reference expressions, and a new concrete test checks mixed-sign
combinations (-5/2, 5/-2, -5/-2, ...) that an unsigned implementation cannot
satisfy.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use claripy.SMod for INT_SREM

Per review, INT_SREM uses claripy.SMod directly instead of the equivalent
in1 - claripy.SDiv(in1, in2) * in2. Verified identical to a truncated-toward-zero
reference over 100k random 64-bit pairs, including the INT_MIN / -1 corner.

* Address pcode signed arithmetic review comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-31 12:23:05 -07:00
..
light Support native AIL Abs expressions in light engines (#6683) 2026-07-24 00:43:03 -07:00
pcode Fix signed division and remainder in the pcode engine (#6739) 2026-07-31 12:23:05 -07:00
vex Enable ruff isort rule (#6452) 2026-06-02 14:48:07 -07:00
__init__.py tests: Add missing __init__.py files for test discovery (#3498) 2022-08-29 23:10:42 -07:00
test_actions.py Enable ruff isort rule (#6452) 2026-06-02 14:48:07 -07:00
test_hook.py Enable ruff isort rule (#6452) 2026-06-02 14:48:07 -07:00
test_java.py [pre-commit.ci] pre-commit autoupdate (#6721) 2026-07-29 13:46:11 -07:00
test_unicorn.py unicorn: Add padding to the lifting buffer in thumb mode (#6412) 2026-05-19 13:10:58 -07:00