Skip to content

Commit 1d6d39b

Browse files
committed
Deduplicate output streams in smt2_convt::write_footer()
This fixes bugs arising from some of the member functions of `smt2::convt` writing to an `os` argument and some of the them writing to `smt2_convt::out`. This was causing some of the generated text to be written out when using `--outfile` argument with cbmc, but not without it. It might be easier to understand `smt2_convt` if the output stream was passed as an argument to the member functions, instead of kept as a member variable. This commit replaces the arguments with references to the member variable because it is a less wide sweeping change and it still solves the bugs. The address_space_size_limit3 test is disabled with smt2, because the output of this test was already different between the sat and smt2 backends and therefore it was already not producing the correct output. Presumably this test was returning the expected `VERIFICATION FAILED` result for the wrong reasons. The `VERIFICATION FAILED` result is only returned in the case where the object size limits are missing. Further work will be needed to properly debug the support for `--pointer-check` with smt2.
1 parent 5b8e8fa commit 1d6d39b

File tree

14 files changed

+41
-35
lines changed

14 files changed

+41
-35
lines changed

regression/cbmc/Malloc6/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/Pointer1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/Pointer28/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check --little-endian
44
^EXIT=0$

regression/cbmc/Pointer4/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/String8/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc/String_Abstraction7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--string-abstraction --pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc/address_space_size_limit3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE broken-smt-backend
22
main.i
33
--32 --little-endian --object-bits 25 --pointer-check
44
^EXIT=10$

regression/cbmc/null7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/struct7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc/void_pointer2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33
--pointer-check --no-simplify --unwind 3
44
^EXIT=0$

src/solvers/smt2/smt2_conv.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,55 +176,55 @@ void smt2_convt::write_header()
176176
out << "(set-logic " << logic << ")" << "\n";
177177
}
178178

179-
void smt2_convt::write_footer(std::ostream &os)
179+
void smt2_convt::write_footer()
180180
{
181-
os << "\n";
181+
out << "\n";
182182

183183
// fix up the object sizes
184184
for(const auto &object : object_sizes)
185185
define_object_size(object.second, object.first);
186186

187187
if(use_check_sat_assuming && !assumptions.empty())
188188
{
189-
os << "(check-sat-assuming (";
189+
out << "(check-sat-assuming (";
190190
for(const auto &assumption : assumptions)
191191
convert_literal(to_literal_expr(assumption).get_literal());
192-
os << "))\n";
192+
out << "))\n";
193193
}
194194
else
195195
{
196196
// add the assumptions, if any
197197
if(!assumptions.empty())
198198
{
199-
os << "; assumptions\n";
199+
out << "; assumptions\n";
200200

201201
for(const auto &assumption : assumptions)
202202
{
203-
os << "(assert ";
203+
out << "(assert ";
204204
convert_literal(to_literal_expr(assumption).get_literal());
205-
os << ")"
206-
<< "\n";
205+
out << ")"
206+
<< "\n";
207207
}
208208
}
209209

210-
os << "(check-sat)\n";
210+
out << "(check-sat)\n";
211211
}
212212

213-
os << "\n";
213+
out << "\n";
214214

215215
if(solver!=solvert::BOOLECTOR)
216216
{
217217
for(const auto &id : smt2_identifiers)
218-
os << "(get-value (|" << id << "|))"
219-
<< "\n";
218+
out << "(get-value (|" << id << "|))"
219+
<< "\n";
220220
}
221221

222-
os << "\n";
222+
out << "\n";
223223

224-
os << "(exit)\n";
224+
out << "(exit)\n";
225225

226-
os << "; end of SMT2 file"
227-
<< "\n";
226+
out << "; end of SMT2 file"
227+
<< "\n";
228228
}
229229

230230
void smt2_convt::define_object_size(
@@ -267,7 +267,7 @@ void smt2_convt::define_object_size(
267267

268268
decision_proceduret::resultt smt2_convt::dec_solve()
269269
{
270-
write_footer(out);
270+
write_footer();
271271
out.flush();
272272
return decision_proceduret::resultt::D_ERROR;
273273
}

src/solvers/smt2/smt2_conv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class smt2_convt : public stack_decision_proceduret
9696
resultt dec_solve() override;
9797

9898
void write_header();
99-
void write_footer(std::ostream &);
99+
void write_footer();
100100

101101
// tweaks for arrays
102102
bool use_array_theory(const exprt &);

src/solvers/smt2/smt2_dec.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ decision_proceduret::resultt smt2_dect::dec_solve()
3939
temp_file_stdout("smt2_dec_stdout_", ""),
4040
temp_file_stderr("smt2_dec_stderr_", "");
4141

42-
{
43-
// we write the problem into a file
44-
std::ofstream problem_out(
45-
temp_file_problem(), std::ios_base::out | std::ios_base::trunc);
46-
problem_out << stringstream.str();
47-
write_footer(problem_out);
48-
}
42+
const auto write_problem_to_file = [&](std::ofstream problem_out) {
43+
cached_output << stringstream.str();
44+
stringstream.str(std::string{});
45+
write_footer();
46+
problem_out << cached_output.str() << stringstream.str();
47+
stringstream.str(std::string{});
48+
};
49+
write_problem_to_file(std::ofstream(
50+
temp_file_problem(), std::ios_base::out | std::ios_base::trunc));
4951

5052
std::vector<std::string> argv;
5153
std::string stdin_filename;

src/solvers/smt2/smt2_dec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class smt2_dect : protected smt2_stringstreamt, public smt2_convt
4545
protected:
4646
message_handlert &message_handler;
4747

48+
/// Everything except the footer is cached, so that output files can be
49+
/// rewritten with varying footers.
50+
std::stringstream cached_output;
51+
4852
resultt read_result(std::istream &in);
4953
};
5054

0 commit comments

Comments
 (0)