Skip to content

Commit 3671dbe

Browse files
committed
Add validation messaging for sorts in get-value responses
This case would previously have failed an invariant in the constructor of `smt_get_value_responset::valuation_pairt` however with these changes the error will be reported to the user instead.
1 parent ed19cf1 commit 3671dbe

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/solvers/smt2_incremental/smt_response_validation.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <util/range.h>
2323

2424
#include "smt_array_theory.h"
25+
#include "smt_to_smt2_string.h"
2526

2627
#include <regex>
2728

@@ -288,12 +289,27 @@ validate_valuation_pair(
288289
const irept &pair_parse_tree,
289290
const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
290291
{
292+
using resultt = response_or_errort<smt_get_value_responset::valuation_pairt>;
291293
PRECONDITION(pair_parse_tree.get_sub().size() == 2);
292-
const auto &descriptor = pair_parse_tree.get_sub()[0];
293-
const auto &value = pair_parse_tree.get_sub()[1];
294-
return validation_propagating<smt_get_value_responset::valuation_pairt>(
295-
validate_term(descriptor, identifier_table),
296-
validate_term(value, identifier_table));
294+
const auto descriptor_validation =
295+
validate_term(pair_parse_tree.get_sub()[0], identifier_table);
296+
const auto value_validation =
297+
validate_term(pair_parse_tree.get_sub()[1], identifier_table);
298+
const auto messages =
299+
collect_messages(descriptor_validation, value_validation);
300+
if(!messages.empty())
301+
return resultt{messages};
302+
const auto &valid_descriptor = *descriptor_validation.get_if_valid();
303+
const auto &valid_value = *value_validation.get_if_valid();
304+
if(valid_descriptor.get_sort() != valid_value.get_sort())
305+
{
306+
return resultt{
307+
"Mismatched descriptor and value sorts in - " +
308+
print_parse_tree(pair_parse_tree) + "\nDescriptor has sort " +
309+
smt_to_smt2_string(valid_descriptor.get_sort()) + "\nValue has sort " +
310+
smt_to_smt2_string(valid_value.get_sort())};
311+
}
312+
return resultt{{valid_descriptor, valid_value}};
297313
}
298314

299315
/// \returns: A response or error in the case where the parse tree appears to be

unit/solvers/smt2_incremental/smt_response_validation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,19 @@ TEST_CASE("smt get-value response validation", "[core][smt2_incremental]")
339339
*empty_pair.get_if_error() ==
340340
std::vector<std::string>{
341341
"Unrecognised SMT term - \"\".", "Unrecognised SMT term - \"\"."});
342+
SECTION("Mismatched descriptor and value sorts")
343+
{
344+
const response_or_errort<smt_responset> mismatched_pair =
345+
validate_smt_response(
346+
*smt2irep("((foo #x2A)))").parsed_output,
347+
table_with_identifiers({{"foo", smt_bool_sortt{}}}));
348+
CHECK(
349+
*mismatched_pair.get_if_error() ==
350+
std::vector<std::string>{"Mismatched descriptor and value sorts in - \n"
351+
"0: foo\n"
352+
"1: #x2A\n"
353+
"Descriptor has sort Bool\n"
354+
"Value has sort (_ BitVec 8)"});
355+
}
342356
}
343357
}

0 commit comments

Comments
 (0)