Add string type support to SMT back-end#8838
Add string type support to SMT back-end#8838tautschnig wants to merge 2 commits intodiffblue:developfrom
string type support to SMT back-end#8838Conversation
We can safely thread through string operations to the back-end as SMT solvers now have support for the theory of strings.
There was a problem hiding this comment.
Pull request overview
This pull request adds basic string type support to the SMT2 backend solver, enabling SMT solvers to handle string operations using the SMT-LIB theory of strings.
Changes:
- Added support for converting string types to SMT2 "String" type
- Implemented string constant conversion with escaping for double quotes and backslashes
- Added special handling for Str.Concat function application to convert to SMT-LIB str.++ operator
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(fn_name == "Str.Concat" && | ||
| function_application_expr.arguments().size() == 2) | ||
| { | ||
| out << "(str.++ "; | ||
| convert_expr(function_application_expr.arguments()[0]); | ||
| out << ' '; | ||
| convert_expr(function_application_expr.arguments()[1]); |
There was a problem hiding this comment.
The str.++ (string concatenation) operation in SMT-LIB 2 can take any number of arguments (including 0, 1, or more than 2), but this implementation only handles exactly 2 arguments. When there are != 2 arguments, it falls through to the else case which will output "Str.Concat" instead of "str.++". Consider removing the size check or handling variable numbers of arguments to ensure all Str.Concat calls are properly converted to str.++.
| if(fn_name == "Str.Concat" && | |
| function_application_expr.arguments().size() == 2) | |
| { | |
| out << "(str.++ "; | |
| convert_expr(function_application_expr.arguments()[0]); | |
| out << ' '; | |
| convert_expr(function_application_expr.arguments()[1]); | |
| if(fn_name == "Str.Concat") | |
| { | |
| out << "(str.++"; | |
| for(const auto &op : function_application_expr.arguments()) | |
| { | |
| out << ' '; | |
| convert_expr(op); | |
| } |
| UNEXPECTEDCASE("unsuppored range type"); | ||
| out << "(_ BitVec " << address_bits(size) << ")"; | ||
| } | ||
| else if(type.id()==ID_string) |
There was a problem hiding this comment.
Inconsistent spacing around the == operator. The codebase convention in this file is to use no spaces (e.g., type.id()==ID_string on line 6025, expr_type.id()==ID_string on line 3782). This line has spaces around == which is inconsistent with the rest of the file.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8838 +/- ##
===========================================
- Coverage 80.00% 80.00% -0.01%
===========================================
Files 1700 1700
Lines 188252 188273 +21
Branches 73 73
===========================================
+ Hits 150613 150621 +8
- Misses 37639 37652 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
We can safely thread through string operations to the back-end as SMT solvers now have support for the theory of strings.