Skip to content

Commit 76f37ce

Browse files
authored
Merge pull request #5791 from diffblue/smt2-uf
SMT2 uninterpreted functions
2 parents 3199c71 + 2019acb commit 76f37ce

File tree

8 files changed

+63
-22
lines changed

8 files changed

+63
-22
lines changed

regression/cbmc/uninterpreted_function/uf2.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
int __CPROVER_uninterpreted_f(int, int);
2+
__CPROVER_bool __CPROVER_uninterpreted_g(int, int);
23

34
main()
45
{
@@ -8,5 +9,11 @@ main()
89
int inst2 = __CPROVER_uninterpreted_f(1, b);
910

1011
if(a == b)
11-
__CPROVER_assert(inst1 == inst2, "functional consistency");
12+
__CPROVER_assert(inst1 == inst2, "functional consistency for f");
13+
14+
int inst3 = __CPROVER_uninterpreted_g(1, a);
15+
int inst4 = __CPROVER_uninterpreted_g(1, b);
16+
17+
if(a == b)
18+
__CPROVER_assert(inst3 == inst4, "functional consistency for g");
1219
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
boolean_uf1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(set-logic QF_UFBV)
2+
3+
(declare-fun myfun ((_ BitVec 32)) Bool)
4+
5+
(assert (myfun (_ bv10 32)))
6+
7+
(declare-const x (_ BitVec 32))
8+
(assert (= x (_ bv10 32)))
9+
(assert (not (myfun x)))
10+
11+
(check-sat)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
uf1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(set-logic QF_UFBV)
2+
3+
(declare-fun myfun ((_ BitVec 32)) (_ BitVec 32))
4+
5+
(assert (= (myfun (_ bv10 32)) (_ bv20 32)))
6+
7+
(declare-const x (_ BitVec 32))
8+
(assert (= x (_ bv10 32)))
9+
(assert (= (myfun x) (_ bv30 32)))
10+
11+
(check-sat)

src/solvers/flattening/boolbv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ literalt boolbvt::convert_rest(const exprt &expr)
565565
else if(op.type().id() == ID_fixedbv)
566566
return const_literal(true);
567567
}
568+
else if(expr.id() == ID_function_application)
569+
{
570+
functions.record(to_function_application_expr(expr));
571+
return prop.new_variable();
572+
}
568573

569574
return SUB::convert_rest(expr);
570575
}

src/solvers/smt2/smt2_parser.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,19 +1223,8 @@ typet smt2_parsert::function_signature_declaration()
12231223
mathematical_function_typet::domaint domain;
12241224

12251225
while(smt2_tokenizer.peek() != smt2_tokenizert::CLOSE)
1226-
{
1227-
if(next_token() != smt2_tokenizert::OPEN)
1228-
throw error("expected '(' at beginning of parameter");
1229-
1230-
if(next_token() != smt2_tokenizert::SYMBOL)
1231-
throw error("expected symbol in parameter");
1232-
12331226
domain.push_back(sort());
12341227

1235-
if(next_token() != smt2_tokenizert::CLOSE)
1236-
throw error("expected ')' at end of parameter");
1237-
}
1238-
12391228
next_token(); // eat the ')'
12401229

12411230
typet codomain = sort();

src/solvers/smt2/smt2_solver.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,22 @@ void smt2_solvert::expand_function_applications(exprt &expr)
102102
domain.size() == app.arguments().size(),
103103
"number of parameters must match number of arguments");
104104

105-
replace_symbolt replace_symbol;
106-
107-
for(std::size_t i = 0; i < domain.size(); i++)
105+
// Does it have a definition? It's otherwise uninterpreted.
106+
if(!f.definition.is_nil())
108107
{
109-
replace_symbol.insert(
110-
symbol_exprt(f.parameters[i], domain[i]), app.arguments()[i]);
108+
replace_symbolt replace_symbol;
109+
110+
for(std::size_t i = 0; i < domain.size(); i++)
111+
{
112+
replace_symbol.insert(
113+
symbol_exprt(f.parameters[i], domain[i]), app.arguments()[i]);
114+
}
115+
116+
exprt body = f.definition;
117+
replace_symbol(body);
118+
expand_function_applications(body);
119+
expr = body;
111120
}
112-
113-
exprt body = f.definition;
114-
replace_symbol(body);
115-
expand_function_applications(body);
116-
expr = body;
117121
}
118122
}
119123
}

0 commit comments

Comments
 (0)