32
32
#include < util/simplify_expr.h>
33
33
#include < util/std_expr.h>
34
34
#include < util/string2int.h>
35
+ #include < util/string_constant.h>
35
36
36
37
#include < goto-programs/cfg.h>
37
38
#include < goto-programs/class_hierarchy.h>
38
39
#include < goto-programs/resolve_inherited_component.h>
40
+
39
41
#include < analyses/cfg_dominators.h>
42
+ #include < analyses/uncaught_exceptions_analysis.h>
40
43
41
44
#include < limits>
42
45
#include < algorithm>
@@ -2248,10 +2251,40 @@ void java_bytecode_convert_methodt::convert_athrow(
2248
2251
codet &c,
2249
2252
exprt::operandst &results) const
2250
2253
{
2251
- side_effect_expr_throwt throw_expr;
2252
- throw_expr.add_source_location () = location;
2253
- throw_expr.copy_to_operands (op[0 ]);
2254
- c = code_expressiont (throw_expr);
2254
+ if (
2255
+ !throw_assertion_error &&
2256
+ uncaught_exceptions_domaint::get_exception_type (op[0 ].type ()) ==
2257
+ " java::java.lang.AssertionError" )
2258
+ {
2259
+ // we translate athrow into
2260
+ // ASSERT false;
2261
+ // ASSUME false:
2262
+ code_assertt assert_code;
2263
+ assert_code.assertion () = false_exprt ();
2264
+ source_locationt assert_location = location; // copy
2265
+ assert_location.set_comment (" assertion at " + location.as_string ());
2266
+ assert_location.set (" user-provided" , true );
2267
+ assert_location.set_property_class (ID_assertion);
2268
+ assert_code.add_source_location () = assert_location;
2269
+
2270
+ code_assumet assume_code;
2271
+ assume_code.assumption () = false_exprt ();
2272
+ source_locationt assume_location = location; // copy
2273
+ assume_location.set (" user-provided" , true );
2274
+ assume_code.add_source_location () = assume_location;
2275
+
2276
+ code_blockt ret_block;
2277
+ ret_block.move_to_operands (assert_code);
2278
+ ret_block.move_to_operands (assume_code);
2279
+ c = ret_block;
2280
+ }
2281
+ else
2282
+ {
2283
+ side_effect_expr_throwt throw_expr;
2284
+ throw_expr.add_source_location () = location;
2285
+ throw_expr.copy_to_operands (op[0 ]);
2286
+ c = code_expressiont (throw_expr);
2287
+ }
2255
2288
results[0 ] = op[0 ];
2256
2289
}
2257
2290
@@ -3055,6 +3088,7 @@ void java_bytecode_convert_method(
3055
3088
symbol_table_baset &symbol_table,
3056
3089
message_handlert &message_handler,
3057
3090
size_t max_array_length,
3091
+ bool throw_assertion_error,
3058
3092
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
3059
3093
java_string_library_preprocesst &string_preprocess,
3060
3094
const class_hierarchyt &class_hierarchy)
@@ -3073,6 +3107,7 @@ void java_bytecode_convert_method(
3073
3107
symbol_table,
3074
3108
message_handler,
3075
3109
max_array_length,
3110
+ throw_assertion_error,
3076
3111
needed_lazy_methods,
3077
3112
string_preprocess,
3078
3113
class_hierarchy);
0 commit comments