File tree 2 files changed +36
-25
lines changed 2 files changed +36
-25
lines changed Original file line number Diff line number Diff line change @@ -789,6 +789,16 @@ void smt2_convt::convert_address_of_rec(
789
789
expr.id_string ());
790
790
}
791
791
792
+ static bool has_quantifier (const exprt &expr)
793
+ {
794
+ bool result = false ;
795
+ expr.visit_post ([&result](const exprt &node) {
796
+ if (node.id () == ID_exists || node.id () == ID_forall)
797
+ result = true ;
798
+ });
799
+ return result;
800
+ }
801
+
792
802
literalt smt2_convt::convert (const exprt &expr)
793
803
{
794
804
PRECONDITION (expr.type ().id () == ID_bool);
@@ -818,13 +828,28 @@ literalt smt2_convt::convert(const exprt &expr)
818
828
// store and in future we use the literal instead of the whole expression
819
829
// Note that here we are always converting, so we do not need to consider
820
830
// other literal kinds, only "|B###|"
821
- defined_expressions[expr] =
822
- std::string{" |B" } + std::to_string (l.var_no ()) + " |" ;
823
- out << " (define-fun " ;
824
- convert_literal (l);
825
- out << " () Bool " ;
826
- convert_expr (prepared_expr);
827
- out << " )" << " \n " ;
831
+
832
+ // Z3 refuses get-value when a defined symbol contains a quantifier.
833
+ if (has_quantifier (prepared_expr))
834
+ {
835
+ out << " (declare-fun " ;
836
+ convert_literal (l);
837
+ out << " () Bool)\n " ;
838
+ out << " (assert (= " ;
839
+ convert_literal (l);
840
+ convert_expr (prepared_expr);
841
+ out << " ))\n " ;
842
+ }
843
+ else
844
+ {
845
+ defined_expressions[expr] =
846
+ std::string{" |B" } + std::to_string (l.var_no ()) + " |" ;
847
+ out << " (define-fun " ;
848
+ convert_literal (l);
849
+ out << " () Bool " ;
850
+ convert_expr (prepared_expr);
851
+ out << " )\n " ;
852
+ }
828
853
829
854
return l;
830
855
}
Original file line number Diff line number Diff line change @@ -184,24 +184,10 @@ decision_proceduret::resultt smt2_dect::read_result(std::istream &in)
184
184
if (res != resultt::D_UNSATISFIABLE)
185
185
{
186
186
const auto &message = id2string (parsed.get_sub ()[1 ].id ());
187
- // Special case error handling
188
- if (
189
- solver == solvert::Z3 &&
190
- message.find (" must not contain quantifiers" ) != std::string::npos)
191
- {
192
- // We tried to "(get-value |XXXX|)" where |XXXX| is determined to
193
- // include a quantified expression
194
- // Nothing to do, this should be caught and value assigned by the
195
- // set_to defaults later.
196
- }
197
- // Unhandled error, log the error and report it back up to caller
198
- else
199
- {
200
- messaget log {message_handler};
201
- log .error () << " SMT2 solver returned error message:\n "
202
- << " \t\" " << message << " \" " << messaget::eom;
203
- return decision_proceduret::resultt::D_ERROR;
204
- }
187
+ messaget log {message_handler};
188
+ log .error () << " SMT2 solver returned error message:\n "
189
+ << " \t\" " << message << " \" " << messaget::eom;
190
+ return decision_proceduret::resultt::D_ERROR;
205
191
}
206
192
}
207
193
}
You can’t perform that action at this time.
0 commit comments