@@ -117,10 +117,9 @@ void remove_exceptionst::add_exceptional_returns(
117
117
118
118
// We generate an exceptional return value for any function that
119
119
// contains a throw or a function call that may escape exceptions.
120
- bool add_exceptional_var=false ;
121
- bool has_uncaught_exceptions=false ;
122
120
forall_goto_program_instructions (instr_it, goto_program)
123
121
{
122
+ bool has_uncaught_exceptions=false ;
124
123
if (instr_it->is_function_call ())
125
124
{
126
125
const exprt &function_expr=
@@ -131,53 +130,53 @@ void remove_exceptionst::add_exceptional_returns(
131
130
has_uncaught_exceptions=!exceptions_map[function_name].empty ();
132
131
}
133
132
134
- const exprt &exc =
135
- uncaught_exceptions_domaint::get_exception_symbol (instr_it->code );
136
- bool assertion_error =
137
- id2string (uncaught_exceptions_domaint::get_static_type (exc.type ())).
138
- find (" java.lang.AssertionError" )!=std::string::npos;
133
+ bool assertion_error=false ;
134
+ if (instr_it->is_throw ())
135
+ {
136
+ const exprt &exc =
137
+ uncaught_exceptions_domaint::get_exception_symbol (instr_it->code );
138
+ assertion_error =
139
+ id2string (uncaught_exceptions_domaint::get_exception_type (exc.type ())).
140
+ find (" java.lang.AssertionError" )!=std::string::npos;
141
+ }
139
142
140
- // if we find a throw that is not AssertionError of a function call
143
+ // if we find a throw different from AssertionError or a function call
141
144
// that may escape exceptions, then we add an exceptional return
142
145
// variable
143
146
if ((instr_it->is_throw () && !assertion_error)
144
147
|| has_uncaught_exceptions)
145
148
{
146
- add_exceptional_var=true ;
149
+ // look up the function symbol
150
+ symbol_tablet::symbolst::iterator s_it=
151
+ symbol_table.symbols .find (function_id);
152
+
153
+ assert (s_it!=symbol_table.symbols .end ());
154
+
155
+ auxiliary_symbolt new_symbol;
156
+ new_symbol.is_static_lifetime =true ;
157
+ new_symbol.module =function_symbol.module ;
158
+ new_symbol.base_name =id2string (function_symbol.base_name )+EXC_SUFFIX;
159
+ new_symbol.name =id2string (function_symbol.name )+EXC_SUFFIX;
160
+ new_symbol.mode =function_symbol.mode ;
161
+ new_symbol.type =typet (ID_pointer, empty_typet ());
162
+ symbol_table.add (new_symbol);
163
+
164
+ // initialize the exceptional return with NULL
165
+ symbol_exprt lhs_expr_null=new_symbol.symbol_expr ();
166
+ null_pointer_exprt rhs_expr_null ((pointer_typet (empty_typet ())));
167
+ goto_programt::targett t_null=
168
+ goto_program.insert_before (goto_program.instructions .begin ());
169
+ t_null->make_assignment ();
170
+ t_null->source_location =
171
+ goto_program.instructions .begin ()->source_location ;
172
+ t_null->code =code_assignt (
173
+ lhs_expr_null,
174
+ rhs_expr_null);
175
+ t_null->function =function_id;
176
+
147
177
break ;
148
178
}
149
179
}
150
-
151
- if (add_exceptional_var)
152
- {
153
- // look up the function symbol
154
- symbol_tablet::symbolst::iterator s_it=
155
- symbol_table.symbols .find (function_id);
156
-
157
- assert (s_it!=symbol_table.symbols .end ());
158
-
159
- auxiliary_symbolt new_symbol;
160
- new_symbol.is_static_lifetime =true ;
161
- new_symbol.module =function_symbol.module ;
162
- new_symbol.base_name =id2string (function_symbol.base_name )+EXC_SUFFIX;
163
- new_symbol.name =id2string (function_symbol.name )+EXC_SUFFIX;
164
- new_symbol.mode =function_symbol.mode ;
165
- new_symbol.type =typet (ID_pointer, empty_typet ());
166
- symbol_table.add (new_symbol);
167
-
168
- // initialize the exceptional return with NULL
169
- symbol_exprt lhs_expr_null=new_symbol.symbol_expr ();
170
- null_pointer_exprt rhs_expr_null ((pointer_typet (empty_typet ())));
171
- goto_programt::targett t_null=
172
- goto_program.insert_before (goto_program.instructions .begin ());
173
- t_null->make_assignment ();
174
- t_null->source_location =
175
- goto_program.instructions .begin ()->source_location ;
176
- t_null->code =code_assignt (
177
- lhs_expr_null,
178
- rhs_expr_null);
179
- t_null->function =function_id;
180
- }
181
180
}
182
181
183
182
/* ******************************************************************\
@@ -293,7 +292,7 @@ void remove_exceptionst::instrument_throw(
293
292
const exprt &exc_expr=
294
293
uncaught_exceptions_domaint::get_exception_symbol (instr_it->code );
295
294
bool assertion_error=id2string (
296
- uncaught_exceptions_domaint::get_static_type (exc_expr.type ())).
295
+ uncaught_exceptions_domaint::get_exception_type (exc_expr.type ())).
297
296
find (" java.lang.AssertionError" )!=std::string::npos;
298
297
299
298
// we don't count AssertionError (we couldn't catch it anyway
@@ -360,11 +359,6 @@ void remove_exceptionst::instrument_throw(
360
359
t_dead->function =instr_it->function ;
361
360
}
362
361
363
- // replace "throw x;" by "f#exception_value=x;"
364
- // exprt exc_expr=instr_it->code;
365
- // while(exc_expr.id()!=ID_symbol && exc_expr.has_operands())
366
- // exc_expr=exc_expr.op0();
367
-
368
362
// add the assignment with the appropriate cast
369
363
code_assignt assignment (typecast_exprt (exc_thrown, exc_expr.type ()),
370
364
exc_expr);
0 commit comments