Skip to content

Commit ffc52fb

Browse files
committed
Error handling cleanup in expr_initializer.cpp (and implied changes)
1 parent d0c36a7 commit ffc52fb

File tree

3 files changed

+11
-42
lines changed

3 files changed

+11
-42
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: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,10 @@ bool static_lifetime_init(
117117

118118
if(symbol.value.is_nil())
119119
{
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-
}
120+
namespacet ns(symbol_table);
121+
rhs = zero_initializer(symbol.type, symbol.location, ns, message_handler);
122+
INVARIANT(
123+
rhs.is_not_nil(), "result of zero-initialization must be non-nil");
130124
}
131125
else
132126
rhs=symbol.value;

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)