-
Notifications
You must be signed in to change notification settings - Fork 273
SMT2 type checking for define-fun #3421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
function-application1.smt2 | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^unsat$ | ||
-- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(set-logic QF_BV) | ||
|
||
(define-fun min ((a (_ BitVec 8)) (b (_ BitVec 8))) (_ BitVec 8) | ||
(ite (bvule a b) a b)) | ||
|
||
(define-fun p1 () Bool (= (min #x01 #x02) #x01)) | ||
(define-fun p2 () Bool (= (min #xff #xfe) #xfe)) | ||
|
||
; all must be true | ||
|
||
(assert (not (and p1 p2))) | ||
|
||
(check-sat) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
function-application2.smt2 | ||
|
||
^EXIT=134$ | ||
^SIGNAL=0$ | ||
^line 5: type mismatch in function definition: expected `\(_ BitVec 16\)' but got `\(_ BitVec 8\)'$ | ||
-- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(set-logic QF_BV) | ||
|
||
; the range type doesn't match! | ||
(define-fun min ((a (_ BitVec 8)) (b (_ BitVec 8))) (_ BitVec 16) | ||
(ite (bvule a b) a b)) | ||
|
||
(define-fun p1 () Bool (= (min #x01 #x02) #x01)) | ||
(define-fun p2 () Bool (= (min #xff #xfe) #xfe)) | ||
|
||
; all must be true | ||
|
||
(assert (not (and p1 p2))) | ||
|
||
(check-sat) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,12 +58,14 @@ rm Float8/test.desc | |
rm Free2/test.desc | ||
rm Function1/test.desc | ||
rm Function_Pointer3/test.desc | ||
rm Initialization6/test.desc | ||
rm Linking4/test.desc | ||
rm Linking7/test.desc | ||
rm Malloc17/test.desc | ||
rm Malloc18/test.desc | ||
rm Malloc19/test.desc | ||
rm Malloc20/test.desc | ||
rm Malloc21/test.desc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am surprised that this is now causing more failures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be expected: the solver is now less permissive than it used to be. These two tests indicate cases in which the back-end generates invalid SMT-LIB files. |
||
rm Malloc23/test.desc | ||
rm Malloc24/test.desc | ||
rm Memmove1/test.desc | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,22 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/arith_tools.h> | ||
|
||
std::ostream &operator<<(std::ostream &out, const smt2_parsert::smt2_format &f) | ||
{ | ||
if(f.type.id() == ID_unsignedbv) | ||
out << "(_ BitVec " << to_unsignedbv_type(f.type).get_width() << ')'; | ||
else if(f.type.id() == ID_bool) | ||
out << "Bool"; | ||
else if(f.type.id() == ID_integer) | ||
out << "Int"; | ||
else if(f.type.id() == ID_real) | ||
out << "Real"; | ||
else | ||
out << "? " << f.type.id(); | ||
|
||
return out; | ||
} | ||
|
||
void smt2_parsert::command_sequence() | ||
{ | ||
exit=false; | ||
|
@@ -360,8 +376,8 @@ exprt smt2_parsert::multi_ary(irep_idt id, const exprt::operandst &op) | |
{ | ||
error() << "expression must have operands with matching types," | ||
" but got `" | ||
<< op[0].type().pretty() | ||
<< "' and `" << op[i].type().pretty() << '\'' << eom; | ||
<< smt2_format(op[0].type()) << "' and `" | ||
<< smt2_format(op[i].type()) << '\'' << eom; | ||
return nil_exprt(); | ||
} | ||
} | ||
|
@@ -385,8 +401,8 @@ exprt smt2_parsert::binary_predicate(irep_idt id, const exprt::operandst &op) | |
{ | ||
error() << "expression must have operands with matching types," | ||
" but got `" | ||
<< op[0].type().pretty() | ||
<< "' and `" << op[1].type().pretty() << '\'' << eom; | ||
<< smt2_format(op[0].type()) << "' and `" | ||
<< smt2_format(op[1].type()) << '\'' << eom; | ||
return nil_exprt(); | ||
} | ||
|
||
|
@@ -1187,6 +1203,26 @@ void smt2_parsert::command(const std::string &c) | |
auto signature=function_signature_definition(); | ||
exprt body=expression(); | ||
|
||
// check type of body | ||
if(signature.id() == ID_mathematical_function) | ||
{ | ||
const auto &f_signature = to_mathematical_function_type(signature); | ||
if(body.type() != f_signature.codomain()) | ||
{ | ||
error() << "type mismatch in function definition: expected `" | ||
<< smt2_format(f_signature.codomain()) << "' but got `" | ||
<< smt2_format(body.type()) << '\'' << eom; | ||
return; | ||
} | ||
} | ||
else if(body.type() != signature) | ||
{ | ||
error() << "type mismatch in function definition: expected `" | ||
<< smt2_format(signature) << "' but got `" | ||
<< smt2_format(body.type()) << '\'' << eom; | ||
return; | ||
} | ||
|
||
// set up the entry | ||
auto &entry=id_map[id]; | ||
entry.type=signature; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the exit code is useless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most solvers seem to do the "continued-execution" error handling from the SMT-LIB standard; yes, the exit code is then used for SAT/UNSAT only.