Skip to content

Commit 3b0409b

Browse files
committed
Reading/writing goto binaries: consistently use return values
Always use the return value to communicate errors, not a mix of return values and exceptions.
1 parent 2e6200a commit 3b0409b

File tree

8 files changed

+35
-23
lines changed

8 files changed

+35
-23
lines changed

src/goto-analyzer/static_simplifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ bool static_simplifier(
190190
goto_model.goto_functions.update();
191191

192192
m.status() << "Writing goto binary" << messaget::eom;
193-
return write_goto_binary(out,
194-
ns.get_symbol_table(),
195-
goto_model.goto_functions);
193+
return write_goto_binary(
194+
out, ns.get_symbol_table(), goto_model.goto_functions, message_handler);
196195
}

src/goto-cc/compile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ bool compilet::write_bin_object_file(
601601
return true;
602602
}
603603

604-
if(write_goto_binary(outfile, src_goto_model))
604+
if(write_goto_binary(outfile, src_goto_model, message_handler))
605605
return true;
606606

607607
const auto cnt = function_body_count(src_goto_model.goto_functions);

src/goto-harness/goto_harness_parse_options.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,13 @@ int goto_harness_parse_optionst::doit()
163163
}
164164
else
165165
{
166-
write_goto_binary(
167-
got_harness_config.out_file, goto_model, log.get_message_handler());
166+
if(write_goto_binary(
167+
got_harness_config.out_file, goto_model, log.get_message_handler()))
168+
{
169+
throw deserialization_exceptiont{
170+
"failed to write goto program to file '" + got_harness_config.out_file +
171+
"'"};
172+
}
168173
}
169174

170175
return CPROVER_EXIT_SUCCESS;

src/goto-programs/read_bin_goto_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class symbol_table_baset;
2121
class goto_functionst;
2222
class message_handlert;
2323

24-
bool read_bin_goto_object(
24+
[[nodiscard]] bool read_bin_goto_object(
2525
std::istream &in,
2626
const std::string &filename,
2727
symbol_table_baset &symbol_table,

src/goto-programs/read_goto_binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool is_goto_binary(const std::string &filename, message_handlert &);
2929
/// \param [out] dest: GOTO model to update.
3030
/// \param message_handler: for diagnostics
3131
/// \return True on error, false otherwise
32-
bool read_objects_and_link(
32+
[[nodiscard]] bool read_objects_and_link(
3333
const std::list<std::string> &file_names,
3434
goto_modelt &dest,
3535
message_handlert &message_handler);

src/goto-programs/write_goto_binary.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ Author: CM Wintersteiger
1111

1212
#include "write_goto_binary.h"
1313

14-
#include <fstream>
15-
16-
#include <util/exception_utils.h>
1714
#include <util/irep_serialization.h>
1815
#include <util/message.h>
1916

2017
#include <goto-programs/goto_model.h>
2118

19+
#include <fstream>
20+
2221
/// Writes the symbol table to file.
2322
static void write_symbol_table_binary(
2423
std::ostream &out,
@@ -144,12 +143,14 @@ static void write_goto_binary(
144143
bool write_goto_binary(
145144
std::ostream &out,
146145
const goto_modelt &goto_model,
146+
message_handlert &message_handler,
147147
int version)
148148
{
149149
return write_goto_binary(
150150
out,
151151
goto_model.symbol_table,
152152
goto_model.goto_functions,
153+
message_handler,
153154
version);
154155
}
155156

@@ -158,6 +159,7 @@ bool write_goto_binary(
158159
std::ostream &out,
159160
const symbol_table_baset &symbol_table,
160161
const goto_functionst &goto_functions,
162+
message_handlert &message_handler,
161163
int version)
162164
{
163165
// header
@@ -169,15 +171,19 @@ bool write_goto_binary(
169171

170172
if(version < GOTO_BINARY_VERSION)
171173
{
172-
throw invalid_command_line_argument_exceptiont(
173-
"version " + std::to_string(version) + " no longer supported",
174-
"supported version = " + std::to_string(GOTO_BINARY_VERSION));
174+
messaget message{message_handler};
175+
message.error() << "version " << version << " no longer supported; "
176+
<< "supported version = " << GOTO_BINARY_VERSION
177+
<< messaget::eom;
178+
return true;
175179
}
176180
if(version > GOTO_BINARY_VERSION)
177181
{
178-
throw invalid_command_line_argument_exceptiont(
179-
"unknown goto binary version " + std::to_string(version),
180-
"supported version = " + std::to_string(GOTO_BINARY_VERSION));
182+
messaget message{message_handler};
183+
message.error() << "unknown goto binary version " << version << "; "
184+
<< "supported version = " << GOTO_BINARY_VERSION
185+
<< messaget::eom;
186+
return true;
181187
}
182188
write_goto_binary(out, symbol_table, goto_functions, irepconverter);
183189
return false;
@@ -198,5 +204,5 @@ bool write_goto_binary(
198204
return true;
199205
}
200206

201-
return write_goto_binary(out, goto_model);
207+
return write_goto_binary(out, goto_model, message_handler);
202208
}

src/goto-programs/write_goto_binary.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@ class goto_modelt;
2222
class message_handlert;
2323
class symbol_table_baset;
2424

25-
bool write_goto_binary(
25+
[[nodiscard]] bool write_goto_binary(
2626
std::ostream &out,
2727
const goto_modelt &,
28-
int version=GOTO_BINARY_VERSION);
28+
message_handlert &,
29+
int version = GOTO_BINARY_VERSION);
2930

30-
bool write_goto_binary(
31+
[[nodiscard]] bool write_goto_binary(
3132
std::ostream &out,
3233
const symbol_table_baset &,
3334
const goto_functionst &,
35+
message_handlert &,
3436
int version = GOTO_BINARY_VERSION);
3537

36-
bool write_goto_binary(
38+
[[nodiscard]] bool write_goto_binary(
3739
const std::string &filename,
3840
const goto_modelt &,
3941
message_handlert &);

src/symtab2gb/symtab2gb_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static void run_symtab2gb(
105105
linked_goto_model.symbol_table.swap(linked_symbol_table);
106106
goto_convert(linked_goto_model, message_handler);
107107

108-
if(failed(write_goto_binary(out_file, linked_goto_model)))
108+
if(failed(write_goto_binary(out_file, linked_goto_model, message_handler)))
109109
{
110110
throw system_exceptiont{"failed to write goto binary to " + gb_filename};
111111
}

0 commit comments

Comments
 (0)