Skip to content

Commit d9c7b9e

Browse files
author
Daniel Kroening
committed
smt2 parser: check type of body of function definition
1 parent 691ace0 commit d9c7b9e

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
function-application1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(set-logic QF_BV)
2+
3+
(define-fun min ((a (_ BitVec 8)) (b (_ BitVec 8))) (_ BitVec 8)
4+
(ite (bvule a b) a b))
5+
6+
(define-fun p1 () Bool (= (min #x01 #x02) #x01))
7+
(define-fun p2 () Bool (= (min #xff #xfe) #xfe))
8+
9+
; all must be true
10+
11+
(assert (not (and p1 p2)))
12+
13+
(check-sat)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
function-application2.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^line 5: type mismatch in function definition: expected `\(_ BitVec 16\)' but got `\(_ BitVec 8\)'$
7+
--
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(set-logic QF_BV)
2+
3+
; the range type doesn't match!
4+
(define-fun min ((a (_ BitVec 8)) (b (_ BitVec 8))) (_ BitVec 16)
5+
(ite (bvule a b) a b))
6+
7+
(define-fun p1 () Bool (= (min #x01 #x02) #x01))
8+
(define-fun p2 () Bool (= (min #xff #xfe) #xfe))
9+
10+
; all must be true
11+
12+
(assert (not (and p1 p2)))
13+
14+
(check-sat)

src/solvers/smt2/smt2_parser.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,26 @@ void smt2_parsert::command(const std::string &c)
12011201
auto signature=function_signature_definition();
12021202
exprt body=expression();
12031203

1204+
// check type of body
1205+
if(signature.id() == ID_mathematical_function)
1206+
{
1207+
const auto &f_signature = to_mathematical_function_type(signature);
1208+
if(body.type() != f_signature.codomain())
1209+
{
1210+
error() << "type mismatch in function definition: expected `"
1211+
<< smt2_format(f_signature.codomain()) << "' but got `"
1212+
<< smt2_format(body.type()) << '\'' << eom;
1213+
return;
1214+
}
1215+
}
1216+
else if(body.type() != signature)
1217+
{
1218+
error() << "type mismatch in function definition: expected `"
1219+
<< smt2_format(signature) << "' but got `"
1220+
<< smt2_format(body.type()) << '\'' << eom;
1221+
return;
1222+
}
1223+
12041224
// set up the entry
12051225
auto &entry=id_map[id];
12061226
entry.type=signature;

0 commit comments

Comments
 (0)