Skip to content

Commit c91d2f7

Browse files
Petr BauchPetr Bauch
authored andcommitted
Invariant cleanup goto programs sz
1 parent 5d8326f commit c91d2f7

File tree

7 files changed

+48
-46
lines changed

7 files changed

+48
-46
lines changed

src/goto-programs/set_properties.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "set_properties.h"
1313

14+
#include <util/invariant.h>
15+
1416
#include <algorithm>
1517
#include <unordered_set>
1618

@@ -110,8 +112,11 @@ void set_properties(
110112
if(!it->second.is_inlined())
111113
set_properties(it->second.body, property_set);
112114

113-
if(!property_set.empty())
114-
throw "property "+id2string(*property_set.begin())+" not found";
115+
INVARIANT_WITH_DIAGNOSTICS(
116+
property_set.empty(),
117+
"Property ",
118+
id2string(*property_set.begin()),
119+
" not found.");
115120
}
116121

117122
void label_properties(goto_functionst &goto_functions)

src/goto-programs/show_symbol_table.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <langapi/language.h>
1919
#include <langapi/mode.h>
2020

21+
#include <util/invariant.h>
2122
#include <util/json_irep.h>
2223

2324
#include "goto_model.h"
@@ -51,8 +52,11 @@ void show_symbol_table_brief_plain(
5152
else
5253
{
5354
ptr=get_language_from_mode(symbol.mode);
54-
if(ptr==nullptr)
55-
throw "symbol "+id2string(symbol.name)+" has unknown mode";
55+
INVARIANT_WITH_DIAGNOSTICS(
56+
ptr != nullptr,
57+
"Symbol ",
58+
id2string(symbol.name),
59+
" has unknown mode.");
5660
}
5761

5862
std::string type_str;
@@ -95,8 +99,8 @@ void show_symbol_table_plain(
9599
ptr=get_language_from_mode(symbol.mode);
96100
}
97101

98-
if(!ptr)
99-
throw "symbol "+id2string(symbol.name)+" has unknown mode";
102+
INVARIANT_WITH_DIAGNOSTICS(
103+
ptr != nullptr, "Symbol ", id2string(symbol.name), " has unknown mode.");
100104

101105
std::string type_str, value_str;
102106

@@ -183,8 +187,8 @@ static void show_symbol_table_json_ui(
183187
ptr=get_language_from_mode(symbol.mode);
184188
}
185189

186-
if(!ptr)
187-
throw "symbol "+id2string(symbol.name)+" has unknown mode";
190+
INVARIANT_WITH_DIAGNOSTICS(
191+
ptr != nullptr, "Symbol ", id2string(symbol.name), " has unknown mode.");
188192

189193
std::string type_str, value_str;
190194

@@ -258,8 +262,8 @@ static void show_symbol_table_brief_json_ui(
258262
ptr=get_language_from_mode(symbol.mode);
259263
}
260264

261-
if(!ptr)
262-
throw "symbol "+id2string(symbol.name)+" has unknown mode";
265+
INVARIANT_WITH_DIAGNOSTICS(
266+
ptr != nullptr, "Symbol ", id2string(symbol.name), " has unknown mode.");
263267

264268
std::string type_str, value_str;
265269

src/goto-programs/slice_global_inits.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ Date: December 2016
1515

1616
#include <analyses/call_graph.h>
1717

18+
#include <util/cprover_prefix.h>
1819
#include <util/find_symbols.h>
20+
#include <util/invariant.h>
1921
#include <util/namespace.h>
20-
#include <util/std_expr.h>
21-
#include <util/cprover_prefix.h>
2222
#include <util/prefix.h>
23+
#include <util/std_expr.h>
2324

2425
#include <goto-programs/goto_functions.h>
2526
#include <goto-programs/remove_skip.h>
@@ -32,8 +33,8 @@ void slice_global_inits(goto_modelt &goto_model)
3233
const irep_idt entry_point=goto_functionst::entry_point();
3334
goto_functionst &goto_functions=goto_model.goto_functions;
3435

35-
if(!goto_functions.function_map.count(entry_point))
36-
throw "entry point not found";
36+
INVARIANT(
37+
goto_functions.function_map.count(entry_point), "Entry point not found.");
3738

3839
// Get the call graph restricted to functions reachable from
3940
// the entry point:
@@ -73,7 +74,9 @@ void slice_global_inits(goto_modelt &goto_model)
7374

7475
goto_functionst::function_mapt::iterator f_it;
7576
f_it=goto_functions.function_map.find(INITIALIZE_FUNCTION);
76-
assert(f_it!=goto_functions.function_map.end());
77+
INVARIANT(
78+
f_it != goto_functions.function_map.end(),
79+
"Initialize function not found.");
7780

7881
goto_programt &goto_program=f_it->second.body;
7982

src/goto-programs/string_instrumentation.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/arith_tools.h>
1717
#include <util/c_types.h>
1818
#include <util/config.h>
19+
#include <util/invariant.h>
1920
#include <util/message.h>
20-
#include <util/std_expr.h>
2121
#include <util/std_code.h>
22+
#include <util/std_expr.h>
2223
#include <util/symbol_table.h>
2324

2425
#include <goto-programs/format_strings.h>
@@ -281,7 +282,7 @@ void string_instrumentationt::do_sprintf(
281282
{
282283
error().source_location=target->source_location;
283284
error() << "sprintf expected to have two or more arguments" << eom;
284-
throw 0;
285+
UNREACHABLE;
285286
}
286287

287288
goto_programt tmp;
@@ -324,7 +325,7 @@ void string_instrumentationt::do_snprintf(
324325
error().source_location=target->source_location;
325326
error() << "snprintf expected to have three or more arguments"
326327
<< eom;
327-
throw 0;
328+
UNREACHABLE;
328329
}
329330

330331
goto_programt tmp;
@@ -366,7 +367,7 @@ void string_instrumentationt::do_fscanf(
366367
{
367368
error().source_location=target->source_location;
368369
error() << "fscanf expected to have two or more arguments" << eom;
369-
throw 0;
370+
UNREACHABLE;
370371
}
371372

372373
goto_programt tmp;
@@ -652,7 +653,7 @@ void string_instrumentationt::do_strchr(
652653
{
653654
error().source_location=target->source_location;
654655
error() << "strchr expected to have two arguments" << eom;
655-
throw 0;
656+
UNREACHABLE;
656657
}
657658

658659
goto_programt tmp;
@@ -679,7 +680,7 @@ void string_instrumentationt::do_strrchr(
679680
{
680681
error().source_location=target->source_location;
681682
error() << "strrchr expected to have two arguments" << eom;
682-
throw 0;
683+
UNREACHABLE;
683684
}
684685

685686
goto_programt tmp;
@@ -706,7 +707,7 @@ void string_instrumentationt::do_strstr(
706707
{
707708
error().source_location=target->source_location;
708709
error() << "strstr expected to have two arguments" << eom;
709-
throw 0;
710+
UNREACHABLE;
710711
}
711712

712713
goto_programt tmp;
@@ -740,7 +741,7 @@ void string_instrumentationt::do_strtok(
740741
{
741742
error().source_location=target->source_location;
742743
error() << "strtok expected to have two arguments" << eom;
743-
throw 0;
744+
UNREACHABLE;
744745
}
745746

746747
goto_programt tmp;

src/goto-programs/vcd_goto_trace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Date: June 2011
1313

1414
#include "vcd_goto_trace.h"
1515

16-
#include <cassert>
1716
#include <ctime>
1817

18+
#include <util/invariant.h>
1919
#include <util/numbering.h>
2020
#include <util/pointer_offset_size.h>
2121

@@ -55,7 +55,7 @@ std::string as_vcd_binary(
5555
}
5656
else if(expr.id()==ID_union)
5757
{
58-
assert(expr.operands().size()==1);
58+
INVARIANT(expr.operands().size() == 1, "Union only takes 1 operand.");
5959
return as_vcd_binary(expr.op0(), ns);
6060
}
6161

src/goto-programs/wp.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Author: Daniel Kroening, [email protected]
1313

1414
// #include <langapi/language_util.h>
1515

16-
#include <util/std_expr.h>
17-
#include <util/std_code.h>
1816
#include <util/base_type.h>
17+
#include <util/invariant.h>
18+
#include <util/std_code.h>
19+
#include <util/std_expr.h>
1920

2021
bool has_nondet(const exprt &dest)
2122
{
@@ -263,6 +264,6 @@ exprt wp(
263264
return post; // ignored
264265
else if(statement==ID_fence)
265266
return post; // ignored
266-
else
267-
throw "sorry, wp("+id2string(statement)+"...) not implemented";
267+
INVARIANT_WITH_DIAGNOSTICS(
268+
false, "Sorry, wp(", id2string(statement), "...) is not implemented.");
268269
}

src/goto-programs/write_goto_binary.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Author: CM Wintersteiger
1313

1414
#include <fstream>
1515

16-
#include <util/message.h>
16+
#include <util/invariant.h>
1717
#include <util/irep_serialization.h>
18+
#include <util/message.h>
1819
#include <util/symbol_table.h>
1920

2021
#include <goto-programs/goto_model.h>
@@ -148,22 +149,9 @@ bool write_goto_binary(
148149
irep_serializationt::ireps_containert irepc;
149150
irep_serializationt irepconverter(irepc);
150151

151-
switch(version)
152-
{
153-
case 1:
154-
case 2:
155-
case 3:
156-
throw "version no longer supported";
157-
158-
case 4:
159-
return write_goto_binary_v4(
160-
out, symbol_table, goto_functions, irepconverter);
161-
162-
default:
163-
throw "unknown goto binary version";
164-
}
165-
166-
return false;
152+
INVARIANT(version > 3, "Version no longer supported.");
153+
INVARIANT(version == 4, "Unknown goto binary version.");
154+
return write_goto_binary_v4(out, symbol_table, goto_functions, irepconverter);
167155
}
168156

169157
/// Writes a goto program to disc

0 commit comments

Comments
 (0)