Skip to content

Commit 23deda5

Browse files
author
Daniel Kroening
authored
Merge pull request #3550 from diffblue/smt2_constants
smt2 solver: constants
2 parents 61f07f6 + 7ec5c20 commit 23deda5

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ rm Quantifiers-if/test.desc
6262
rm Quantifiers-initialisation2/test.desc
6363
rm Quantifiers-invalid-var-range/test.desc
6464
rm Quantifiers-not/test.desc
65-
rm Quantifiers-not-exists/test.desc
66-
rm Quantifiers-two-dimension-array/test.desc
6765
rm Quantifiers-type/test.desc
6866
rm Struct_Bytewise2/test.desc
6967
rm Union_Initialization1/test.desc
@@ -92,6 +90,7 @@ rm equality_through_union3/test.desc
9290
rm gcc_bswap1/test.desc
9391
rm gcc_vector1/test.desc
9492
rm graphml_witness1/test.desc
93+
rm integer-assignments1/test.desc
9594
rm memory_allocation1/test.desc
9695
rm pointer-function-parameters-struct-mutual-recursion/test.desc
9796
rm pointer-function-parameters-struct-simple-recursion/test.desc

src/solvers/smt2/smt2_format.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ std::ostream &smt2_format_rec(std::ostream &out, const exprt &expr)
100100
<< smt2_format(with_expr.where()) << ' '
101101
<< smt2_format(with_expr.new_value()) << ')';
102102
}
103+
else if(expr.id() == ID_array_list)
104+
{
105+
const auto &array_list_expr = to_multi_ary_expr(expr);
106+
107+
for(std::size_t i = 0; i < array_list_expr.operands().size(); i += 2)
108+
out << "(store ";
109+
110+
out << "((as const " << smt2_format(expr.type()) << ")) "
111+
<< smt2_format(from_integer(0, expr.type().subtype())) << ')';
112+
113+
for(std::size_t i = 0; i < array_list_expr.operands().size(); i += 2)
114+
{
115+
DATA_INVARIANT(
116+
i < array_list_expr.operands().size() - 1,
117+
"array_list has even number of operands");
118+
out << ' ' << smt2_format(array_list_expr.operands()[i]) << ' '
119+
<< smt2_format(array_list_expr.operands()[i + 1]) << ')';
120+
}
121+
}
103122
else
104123
out << "? " << expr.id();
105124

src/solvers/smt2/smt2_solver.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class smt2_solvert:public smt2_parsert
3434
decision_proceduret &solver;
3535

3636
void command(const std::string &) override;
37-
void define_constants(const exprt &);
37+
void define_constants();
3838
void expand_function_applications(exprt &);
3939

4040
std::set<irep_idt> constants_done;
@@ -47,36 +47,28 @@ class smt2_solvert:public smt2_parsert
4747
} status;
4848
};
4949

50-
void smt2_solvert::define_constants(const exprt &expr)
50+
void smt2_solvert::define_constants()
5151
{
52-
for(const auto &op : expr.operands())
53-
define_constants(op);
54-
55-
if(expr.id()==ID_symbol)
52+
for(const auto &id : id_map)
5653
{
57-
irep_idt identifier=to_symbol_expr(expr).get_identifier();
54+
if(id.second.type.id() == ID_mathematical_function)
55+
continue;
56+
57+
if(id.second.definition.is_nil())
58+
continue;
59+
60+
const irep_idt &identifier = id.first;
5861

5962
// already done?
6063
if(constants_done.find(identifier)!=constants_done.end())
61-
return;
64+
continue;
6265

6366
constants_done.insert(identifier);
6467

65-
auto f_it=id_map.find(identifier);
66-
67-
if(f_it!=id_map.end())
68-
{
69-
const auto &f=f_it->second;
70-
71-
if(f.type.id()!=ID_mathematical_function &&
72-
f.definition.is_not_nil())
73-
{
74-
exprt def=f.definition;
75-
expand_function_applications(def);
76-
define_constants(def); // recursive!
77-
solver.set_to_true(equal_exprt(expr, def));
78-
}
79-
}
68+
exprt def = id.second.definition;
69+
expand_function_applications(def);
70+
solver.set_to_true(
71+
equal_exprt(symbol_exprt(identifier, id.second.type), def));
8072
}
8173
}
8274

@@ -135,12 +127,14 @@ void smt2_solvert::command(const std::string &c)
135127
if(e.is_not_nil())
136128
{
137129
expand_function_applications(e);
138-
define_constants(e);
139130
solver.set_to_true(e);
140131
}
141132
}
142133
else if(c == "check-sat")
143134
{
135+
// add constant definitions as constraints
136+
define_constants();
137+
144138
switch(solver())
145139
{
146140
case decision_proceduret::resultt::D_SATISFIABLE:
@@ -200,12 +194,7 @@ void smt2_solvert::command(const std::string &c)
200194
if(id_map_it == id_map.end())
201195
throw error("unexpected symbol " + id2string(identifier));
202196

203-
exprt value;
204-
205-
if(id_map_it->second.definition.is_nil())
206-
value = solver.get(op);
207-
else
208-
value = solver.get(id_map_it->second.definition);
197+
const exprt value = solver.get(op);
209198

210199
if(value.is_nil())
211200
throw error("no value for " + id2string(identifier));

0 commit comments

Comments
 (0)