Skip to content

Commit 756c0b9

Browse files
committed
Error handling cleanup in expr_initializer.cpp (and implied changes)
1 parent d5535a9 commit 756c0b9

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ bool ansi_c_entry_point(
177177
return false; // give up
178178
}
179179

180-
if(static_lifetime_init(symbol_table, symbol.location, message_handler))
181-
return true;
180+
static_lifetime_init(symbol_table, symbol.location, message_handler);
182181

183182
return generate_ansi_c_start_function(symbol, symbol_table, message_handler);
184183
}

src/linking/static_lifetime_init.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <goto-programs/goto_functions.h>
2424

25-
bool static_lifetime_init(
25+
void static_lifetime_init(
2626
symbol_tablet &symbol_table,
2727
const source_locationt &source_location,
2828
message_handlert &message_handler)
2929
{
30-
namespacet ns(symbol_table);
30+
PRECONDITION(symbol_table.has_symbol(INITIALIZE_FUNCTION));
3131

32-
const auto maybe_symbol=symbol_table.get_writeable(INITIALIZE_FUNCTION);
33-
if(!maybe_symbol)
34-
return false;
35-
symbolt &init_symbol=*maybe_symbol;
32+
const namespacet ns(symbol_table);
33+
34+
symbolt &init_symbol = symbol_table.get_writeable_ref(INITIALIZE_FUNCTION);
3635

3736
init_symbol.value=code_blockt();
3837
init_symbol.value.add_source_location()=source_location;
@@ -117,16 +116,10 @@ bool static_lifetime_init(
117116

118117
if(symbol.value.is_nil())
119118
{
120-
try
121-
{
122-
namespacet ns(symbol_table);
123-
rhs=zero_initializer(symbol.type, symbol.location, ns, message_handler);
124-
assert(rhs.is_not_nil());
125-
}
126-
catch(...)
127-
{
128-
return true;
129-
}
119+
const namespacet ns(symbol_table);
120+
rhs = zero_initializer(symbol.type, symbol.location, ns, message_handler);
121+
INVARIANT(
122+
rhs.is_not_nil(), "result of zero-initialization must be non-nil");
130123
}
131124
else
132125
rhs=symbol.value;
@@ -156,6 +149,4 @@ bool static_lifetime_init(
156149
dest.move_to_operands(function_call);
157150
}
158151
}
159-
160-
return false;
161152
}

src/linking/static_lifetime_init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class message_handlert;
1616
class source_locationt;
1717
class symbol_tablet;
1818

19-
bool static_lifetime_init(
19+
void static_lifetime_init(
2020
symbol_tablet &symbol_table,
2121
const source_locationt &source_location,
2222
message_handlert &message_handler);

src/util/expr_initializer.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
123123
result.add_source_location()=source_location;
124124
return result;
125125
}
126-
else if(type_id==ID_code)
127-
{
128-
error().source_location=source_location;
129-
error() << "cannot initialize code-type" << eom;
130-
throw 0;
131-
}
132126
else if(type_id==ID_array)
133127
{
134128
const array_typet &array_type=to_array_type(type);
@@ -369,35 +363,17 @@ exprt zero_initializer(
369363
const source_locationt &source_location,
370364
const namespacet &ns)
371365
{
372-
std::ostringstream oss;
373-
stream_message_handlert mh(oss);
374-
375-
try
376-
{
377-
expr_initializert<false> z_i(ns, mh);
378-
return z_i(type, source_location);
379-
}
380-
catch(int)
381-
{
382-
throw oss.str();
383-
}
366+
null_message_handlert null_message_handler;
367+
expr_initializert<false> z_i(ns, null_message_handler);
368+
return z_i(type, source_location);
384369
}
385370

386371
exprt nondet_initializer(
387372
const typet &type,
388373
const source_locationt &source_location,
389374
const namespacet &ns)
390375
{
391-
std::ostringstream oss;
392-
stream_message_handlert mh(oss);
393-
394-
try
395-
{
396-
expr_initializert<true> z_i(ns, mh);
397-
return z_i(type, source_location);
398-
}
399-
catch(int)
400-
{
401-
throw oss.str();
402-
}
376+
null_message_handlert null_message_handler;
377+
expr_initializert<true> z_i(ns, null_message_handler);
378+
return z_i(type, source_location);
403379
}

0 commit comments

Comments
 (0)