Skip to content

Commit 845343e

Browse files
authored
Merge pull request #6207 from thomasspriggs/tas/smt2_stream_consistency_for_develop
Fix bugs stemming from duplicate output streams in smt2_convt::write_footer()
2 parents 5b8e8fa + b68902f commit 845343e

File tree

14 files changed

+50
-35
lines changed

14 files changed

+50
-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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ class smt2_convt : public stack_decision_proceduret
9696
resultt dec_solve() override;
9797

9898
void write_header();
99-
void write_footer(std::ostream &);
99+
/// Writes the end of the SMT file to the `smt_convt::out` stream. These parts
100+
/// of the output may be changed when using multiple rounds of solving. They
101+
/// include the following parts of the output file -
102+
/// * The object size definitions.
103+
/// * The assertions based on the `assumptions` member variable.
104+
/// * The `(check-sat)` or `check-sat-assuming` command.
105+
/// * A `(get-value |identifier|)` command for each of the identifiers in
106+
/// `smt2_convt::smt2_identifiers`.
107+
/// * An `(exit)` command.
108+
void write_footer();
100109

101110
// tweaks for arrays
102111
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)