29 const bool _throw_runtime_exceptions,
50 const exprt &array_struct,
55 const exprt &denominator,
63 const exprt &tested_expr,
78 "java.lang.ArithmeticException",
79 "java.lang.ArrayIndexOutOfBoundsException",
80 "java.lang.ClassCastException",
81 "java.lang.NegativeArraySizeException",
82 "java.lang.NullPointerException"};
114 exc_ptr_type,
"new_exception", original_loc,
"new_exception",
symbol_table);
138 const exprt &denominator,
148 "java.lang.ArithmeticException");
151 assertion_loc.
set_comment(
"Denominator should be nonzero");
169 const exprt &array_struct,
177 const and_exprt cond(ge_zero, lt_length);
183 "java.lang.ArrayIndexOutOfBoundsException");
188 low_check_loc.
set_comment(
"Array index should be >= 0");
192 high_check_loc.
set_comment(
"Array index should be < length");
198 return std::move(bounds_checks);
212 const exprt &tested_expr,
228 "java.lang.ClassCastException");
266 original_loc,
"java.lang.NullPointerException");
295 "java.lang.NegativeArraySizeException");
298 check_loc.
set_comment(
"Array size should be >= 0");
314 if(expr_instrumentation->get_statement() == ID_block)
317 block.
add(std::move(*expr_instrumentation));
334 instrumentation.
add(code);
335 code=instrumentation;
348 if(statement==ID_assign)
357 else if(statement==ID_expression)
366 else if(statement==ID_assert)
371 if(code_assert.
assertion().
id()==ID_java_instanceof)
374 const auto & instanceof
382 else if(statement==ID_block)
387 else if(statement==ID_label)
392 else if(statement==ID_ifthenelse)
402 else if(statement==ID_switch)
410 else if(statement==ID_return)
417 else if(statement==ID_function_call)
427 for(
const auto &arg : code_function_call.
arguments())
455 for(
const auto &op : expr.
operands())
458 result.
add(std::move(*op_result));
462 if(expr.
id()==ID_plus &&
463 expr.
get_bool(ID_java_array_access))
468 if(plus_expr.
op0().
id()==ID_member)
471 if(member_expr.
compound().
id() == ID_dereference)
480 result.
add(std::move(bounds_check));
484 else if(expr.
id()==ID_side_effect)
488 if(statement==ID_throw)
495 else if(statement==ID_java_new_array)
503 else if((expr.
id()==ID_div || expr.
id()==ID_mod) &&
504 expr.
type().
id()==ID_signedbv)
510 else if(expr.
id()==ID_dereference &&
511 expr.
get_bool(ID_java_member_access))
517 result.
add(std::move(null_dereference_check));
523 return std::move(result);
547 const bool throw_runtime_exceptions,
552 throw_runtime_exceptions,
556 "java_bytecode_instrument expects a code-typed symbol but was called with"
557 " " +
id2string(symbol.
name) +
" which has a value with an id of " +
578 assert_location.
set_comment(
"no uncaught exception");
581 init_code.
add(std::move(assert_no_exception));
596 const bool throw_runtime_exceptions,
601 throw_runtime_exceptions,
604 std::vector<irep_idt> symbols_to_instrument;
605 for(
const auto &symbol_pair : symbol_table.
symbols)
607 if(symbol_pair.second.value.id() == ID_code)
609 symbols_to_instrument.push_back(symbol_pair.first);
615 for(
const auto &symbol : symbols_to_instrument)
pointer_typet pointer_type(const typet &subtype)
A base class for relations, i.e., binary predicates whose two operands have the same type.
A non-fatal assertion, which checks a condition then permits execution to continue.
const exprt & assertion() const
A goto_instruction_codet representing an assignment in the program.
A codet representing sequential composition of program statements.
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
void add(const codet &code)
codet representation of an expression statement.
const exprt & expression() const
goto_instruction_codet representation of a function call statement.
codet representation of an if-then-else statement.
const codet & then_case() const
const exprt & cond() const
const codet & else_case() const
codet representation of a label for branch targets.
goto_instruction_codet representation of a "return from a function" statement.
const exprt & return_value() const
codet representing a switch statement.
const exprt & value() const
const codet & body() const
Data structure for representing an arbitrary statement in a program.
const irep_idt & get_statement() const
A constant literal expression.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
bool get_bool(const irep_idt &name) const
const irep_idt & id() const
java_bytecode_instrumentt(symbol_table_baset &_symbol_table, const bool _throw_runtime_exceptions, message_handlert &_message_handler)
codet check_array_access(const exprt &array_struct, const exprt &idx, const source_locationt &original_loc)
Checks whether the array access array_struct[idx] is out-of-bounds, and throws ArrayIndexOutofBoundsE...
std::optional< codet > instrument_expr(const exprt &expr)
Computes the instrumentation for expr in the form of either assertions or runtime exceptions.
void operator()(codet &code)
Instruments code.
void prepend_instrumentation(codet &code, code_blockt &instrumentation)
Appends code to instrumentation and overwrites reference code with the augmented block if instrumenta...
void add_expr_instrumentation(code_blockt &block, const exprt &expr)
Checks whether expr requires instrumentation, and if so adds it to block.
codet check_arithmetic_exception(const exprt &denominator, const source_locationt &original_loc)
Checks whether there is a division by zero and throws ArithmeticException if necessary.
const bool throw_runtime_exceptions
message_handlert & message_handler
codet check_array_length(const exprt &length, const source_locationt &original_loc)
Checks whether length >= 0 and throws NegativeArraySizeException/ generates an assertion when necessa...
void instrument_code(codet &code)
Augments code with instrumentation in the form of either assertions or runtime exceptions.
code_ifthenelset throw_exception(const exprt &cond, const source_locationt &original_loc, const irep_idt &exc_name)
Creates a class stub for exc_name and generates a conditional GOTO such that exc_name is thrown when ...
code_ifthenelset check_class_cast(const exprt &tested_expr, const struct_tag_typet &target_type, const source_locationt &original_loc)
Checks whether class1 is an instance of class2 and throws ClassCastException/generates an assertion w...
codet check_null_dereference(const exprt &expr, const source_locationt &original_loc)
Checks whether expr is null and throws NullPointerException/ generates an assertion when necessary; E...
symbol_table_baset & symbol_table
Extract member of struct or union.
const exprt & compound() const
The null pointer constant.
The plus expression Associativity is not specified.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
A side_effect_exprt representation of a side effect that throws an exception.
An expression containing a side effect.
const irep_idt & get_statement() const
void set_comment(const irep_idt &comment)
void set_property_class(const irep_idt &property_class)
const irep_idt & get_line() const
A struct tag type, i.e., struct_typet with an identifier.
std::vector< componentt > componentst
The symbol table base class interface.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
exprt value
Initial value of symbol.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
#define Forall_operands(it, expr)
const code_returnt & to_code_return(const goto_instruction_codet &code)
const code_assignt & to_code_assign(const goto_instruction_codet &code)
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
const std::string & id2string(const irep_idt &d)
void java_bytecode_instrument_symbol(symbol_table_baset &symbol_table, symbolt &symbol, const bool throw_runtime_exceptions, message_handlert &message_handler)
Instruments the code attached to symbol with runtime exceptions or corresponding assertions.
void java_bytecode_instrument_uncaught_exceptions(code_blockt &init_code, const symbolt &exc_symbol, const source_locationt &source_location)
Instruments the start function with an assertion that checks whether an exception has escaped the ent...
void java_bytecode_instrument(symbol_table_baset &symbol_table, const bool throw_runtime_exceptions, message_handlert &message_handler)
Instruments all the code in the symbol_table with runtime exceptions or corresponding assertions.
const std::vector< std::string > exception_needed_classes
Java-specific exprt subclasses.
const java_instanceof_exprt & to_java_instanceof_expr(const exprt &expr)
Cast an exprt to a java_instanceof_exprt.
signedbv_typet java_int_type()
empty_typet java_void_type()
const java_method_typet & to_java_method_type(const typet &type)
symbolt & fresh_java_symbol(const typet &type, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &function_name, symbol_table_baset &symbol_table)
void generate_class_stub(const irep_idt &class_name, symbol_table_baset &symbol_table, message_handlert &message_handler, const struct_union_typet::componentst &componentst)
void merge_source_location_rec(exprt &expr, const source_locationt &source_location)
Attaches a source location to an expression and all of its subexpressions.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
code_blockt create_fatal_assertion(const exprt &condition, const source_locationt &loc)
Create a fatal assertion, which checks a condition and then halts if it does not hold.
const code_ifthenelset & to_code_ifthenelse(const codet &code)
side_effect_exprt & to_side_effect_expr(exprt &expr)
const code_labelt & to_code_label(const codet &code)
const code_switcht & to_code_switch(const codet &code)
code_expressiont & to_code_expression(codet &code)
const code_blockt & to_code_block(const codet &code)
const code_assertt & to_code_assert(const codet &code)
const codet & to_code(const exprt &expr)
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
void check_code(const codet &code, const validation_modet vm)
Check that the given code statement is well-formed (shallow checks only, i.e., enclosed statements,...