Skip to content

SMT2: fix struct_tag missing from datatype_map in cycles - #9222

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/9190-smt2-datatype-map-at
Open

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/9190-smt2-datatype-map-at

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

When find_symbols_rec encounters a struct_tag whose identifier is
already in recstack, it skips the recursion. However, the alias
datatype_map[struct_tag_type] = datatype_map[underlying_struct]
is only created after the recursion returns (outside the recstack
check). If another struct whose datatype is being declared has
this struct_tag as a direct component, convert_type throws
std::out_of_range because the struct_tag has no datatype_map entry.

Additionally, find_symbols_rec used to traverse into code (function
pointer) types, recursing into their parameter and return types.
Since code types are rendered as Bool in SMT-LIB, this traversal is
unnecessary for datatype declarations and can cause struct datatype
declarations to be emitted in the wrong order: a struct discovered
through a function-pointer parameter chain gets its declare-datatypes
emitted before the struct it references, producing an undefined sort
reference that the solver rejects.

The fix has two parts:

  1. When a struct_tag is already in recstack but use_datatypes is true,
    eagerly create the datatype_map alias from the underlying struct
    (which is always registered before its components are recursed).

  2. Skip find_symbols_rec traversal into code types entirely. The
    types referenced through function pointer signatures will be
    discovered independently when expressions of those types appear in
    the formula.

The bug is triggered by Kani-generated goto binaries for Rust code
that uses core::fmt::Formatter, whose type graph cycles through
function pointer parameters (vtable entries). It manifests as
exit status 6 (uncaught std::out_of_range) with --z3 and --cvc5 but
not with --smt2 --outfile (which does not use datatypes).

Fixes #9190

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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).
  • n/a 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.

When find_symbols_rec encounters a struct_tag whose identifier is
already in recstack, it skips the recursion.  However, the alias
  datatype_map[struct_tag_type] = datatype_map[underlying_struct]
is only created after the recursion returns (outside the recstack
check).  If another struct whose datatype is being declared has
this struct_tag as a direct component, convert_type throws
std::out_of_range because the struct_tag has no datatype_map entry.

Additionally, find_symbols_rec used to traverse into code (function
pointer) types, recursing into their parameter and return types.
Since code types are rendered as Bool in SMT-LIB, this traversal is
unnecessary for datatype declarations and can cause struct datatype
declarations to be emitted in the wrong order: a struct discovered
through a function-pointer parameter chain gets its declare-datatypes
emitted before the struct it references, producing an undefined sort
reference that the solver rejects.

The fix has two parts:

1. When a struct_tag is already in recstack but use_datatypes is true,
   eagerly create the datatype_map alias from the underlying struct
   (which is always registered before its components are recursed).

2. Skip find_symbols_rec traversal into code types entirely.  The
   types referenced through function pointer signatures will be
   discovered independently when expressions of those types appear in
   the formula.

The bug is triggered by Kani-generated goto binaries for Rust code
that uses core::fmt::Formatter, whose type graph cycles through
function pointer parameters (vtable entries).  It manifests as
exit status 6 (uncaught std::out_of_range) with --z3 and --cvc5 but
not with --smt2 --outfile (which does not use datatypes).

Fixes diffblue#9190

Co-authored-by: Kiro <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 19:38

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.90%. Comparing base (266f438) to head (34b0e5e).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9222      +/-   ##
===========================================
- Coverage    80.91%   80.90%   -0.01%     
===========================================
  Files         1718     1718              
  Lines       190266   190266              
  Branches        73       73              
===========================================
- Hits        153952   153936      -16     
- Misses       36314    36330      +16     

☔ 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.

This branch has not been deployed

No deployments
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.

--z3/--cvc5: map::at exception (exit status 6) while converting a goto program that contains Rust's core::fmt::Formatter

2 participants