Skip to content

SMT2: only typecast array index for fixed-width bitvector index types#9073

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:strata/smt2-array-index-typecast
Open

SMT2: only typecast array index for fixed-width bitvector index types#9073
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:strata/smt2-array-index-typecast

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

When converting array store/select, typecast the index to the array's index type only when both are fixed-width bitvectors; for mathematical-integer or struct-typed (map key) indices, emit the index directly.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Jun 18, 2026
Copilot AI review requested due to automatic review settings June 18, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adjust SMT2 array store/select index handling to avoid unnecessary typecasts, only casting when both index types are fixed-width bitvectors.

Changes:

  • Conditionally typecast array store indices only when both sides are fixed-width bitvector-like types.
  • Conditionally typecast array select (index) expressions using the same rule, emitting integer/struct indices directly.

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

Comment on lines +4786 to +4796
const typet idx_type = array_type.index_type();
const auto is_bv = [](const typet &t) {
return t.id() == ID_unsignedbv || t.id() == ID_signedbv ||
t.id() == ID_c_bool || t.id() == ID_c_enum ||
t.id() == ID_c_enum_tag;
};
const exprt index =
(idx_type != expr.index().type() && is_bv(idx_type) &&
is_bv(expr.index().type()))
? static_cast<exprt>(typecast_exprt(expr.index(), idx_type))
: expr.index();
Comment on lines +4555 to +4565
const typet idx_type = array_type.index_type();
const auto is_bv = [](const typet &t) {
return t.id() == ID_unsignedbv || t.id() == ID_signedbv ||
t.id() == ID_c_bool || t.id() == ID_c_enum ||
t.id() == ID_c_enum_tag;
};
const exprt where =
(idx_type != expr.where().type() && is_bv(idx_type) &&
is_bv(expr.where().type()))
? static_cast<exprt>(typecast_exprt(expr.where(), idx_type))
: expr.where();
Comment on lines +4783 to +4786
// Typecast the index to the array's index type, but only when both
// types are fixed-width bitvectors. For mathematical integers or
// struct-typed indices (e.g., map keys), emit directly.
const typet idx_type = array_type.index_type();
Comment on lines +4792 to +4796
const exprt index =
(idx_type != expr.index().type() && is_bv(idx_type) &&
is_bv(expr.index().type()))
? static_cast<exprt>(typecast_exprt(expr.index(), idx_type))
: expr.index();
When converting array store/select, typecast the index to the array's index
type only when both are fixed-width bitvectors; for mathematical-integer or
struct-typed (map key) indices, emit the index directly.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig force-pushed the strata/smt2-array-index-typecast branch from a7523db to 326cd10 Compare June 19, 2026 08:20
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.68%. Comparing base (321ba11) to head (326cd10).

Files with missing lines Patch % Lines
src/solvers/smt2/smt2_conv.cpp 78.26% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9073      +/-   ##
===========================================
- Coverage    80.68%   80.68%   -0.01%     
===========================================
  Files         1714     1714              
  Lines       189501   189521      +20     
  Branches        73       73              
===========================================
+ Hits        152902   152917      +15     
- Misses       36599    36604       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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