Skip to content

Comments

Add regression tests for __and__ simplifier with If expressions#696

Open
zardus wants to merge 2 commits intomasterfrom
fix/and-simplifier-if-expressions
Open

Add regression tests for __and__ simplifier with If expressions#696
zardus wants to merge 2 commits intomasterfrom
fix/and-simplifier-if-expressions

Conversation

@zardus
Copy link
Member

@zardus zardus commented Feb 14, 2026

Summary

Test coverage added

  • If(...) & If(...) with arbitrary multi-bit concrete values (the reported crash case)
  • If(cond, 1, 0) & If(cond, 1, 0) optimization with 8-bit values (verifies the optimization still works)
  • If(...) & BVV and BVV & If(...) (mixed operand cases)
  • If(...) | If(...) and If(...) ^ If(...) (bitwise OR and XOR with If expressions)

Test plan

  • All 331 existing tests pass
  • New regression tests pass
  • Verified the bug reproduces on the pre-fix version (parent of dd5b13b)

The fix in dd5b13b (#621) resolved a ClaripyOperationError crash when
the __and__ simplifier encountered If expressions with non-1-bit values
(e.g., 8-bit). The hardcoded BVV(1, 1) comparisons caused a length
mismatch error. This adds regression tests covering:
- If(...) & If(...) with arbitrary multi-bit concrete values
- If(cond, 1, 0) & If(cond, 1, 0) optimization with 8-bit values
- If(...) & BVV and BVV & If(...)
- If expressions with bitwise OR and XOR operators

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings February 14, 2026 21:09
@zardus
Copy link
Member Author

zardus commented Feb 14, 2026

This resulted from a scrape of issues from discord. Not really sure if we need these explicit tests. Can close or merge as we want.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive regression tests for a bug fix (from PR #621) where the bitwise AND simplifier would crash when processing If expressions with non-1-bit values. The fix already exists in the codebase, but these tests ensure the issue doesn't regress in the future.

Changes:

  • Added test_bitwise_and_if_multibyte() to test AND operations on multi-bit If expressions
  • Added test_bitwise_or_xor_if() to test OR and XOR operations on If expressions
  • Tests validate both crash prevention and correct optimization behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

expr = claripy.If(c, claripy.BVV(1, 8), claripy.BVV(2, 8)) & claripy.If(d, claripy.BVV(3, 8), claripy.BVV(4, 8))
assert expr.size() == 8

# If(cond, 1, 0) & If(cond, 1, 0) with 8-bit should still optimize
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "If(cond, 1, 0) & If(cond, 1, 0)" but the test uses different conditions (c and d). Consider updating the comment to say "If(cond1, 1, 0) & If(cond2, 1, 0)" or similar to accurately reflect that different conditions are being used. This would make it clearer that the optimization applies even when the conditions differ.

Suggested change
# If(cond, 1, 0) & If(cond, 1, 0) with 8-bit should still optimize
# If(cond1, 1, 0) & If(cond2, 1, 0) with 8-bit should still optimize (here cond1=c, cond2=d)

Copilot uses AI. Check for mistakes.
@angr-bot
Copy link
Member

Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/claripy_696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants