Go to the documentation of this file.
32 #define JAVA_MAIN_METHOD "main:([Ljava/lang/String;)V"
40 const std::vector<exprt> &arguments,
56 initialize.
mode=ID_java;
59 symbol_table.
add(initialize);
64 if(sym.
type.
id()!=ID_code &&
72 return !sym.
type.
get_bool(ID_C_no_initialization_required);
81 "java::java.lang.Class.cproverInitializeClassLiteral:"
82 "(Ljava/lang/String;ZZZZZZZ)V";
114 bool assume_init_pointers_not_null,
117 bool string_refinement_enabled,
120 std::unordered_set<irep_idt> additional_symbols;
123 const symbolt *class_literal_init_method =
139 string_refinement_enabled);
155 class_literal_init_method->symbol_expr(),
157 address_of_exprt(sym.symbol_expr()),
159 address_of_exprt(class_name_literal),
161 constant_bool(java_class_type.get_is_annotation()),
163 constant_bool(class_is_array),
165 constant_bool(java_class_type.get_interface()),
167 constant_bool(java_class_type.get_synthetic()),
173 constant_bool(java_class_type.get_is_enumeration())});
179 if(!zero_object.has_value())
182 message.
error() <<
"failed to zero-initialize " << sym.
name
193 code_block.
add(std::move(initializer_call));
200 assume_init_pointers_not_null;
203 if(not_allow_null && !is_class_model)
214 pointer_type_selector,
222 code_block.
add(assignment);
225 return additional_symbols;
231 bool assume_init_pointers_not_null,
234 bool string_refinement_enabled,
257 val, symbol_table, string_refinement_enabled);
265 std::set<std::string> symbol_names;
266 for(
const auto &entry : symbol_table.
symbols)
267 symbol_names.insert(
id2string(entry.first));
269 std::set<std::string> additional_symbols;
270 while(!symbol_names.empty() || !additional_symbols.empty())
272 if(!additional_symbols.empty())
273 symbol_names.swap(additional_symbols);
275 for(
const auto &symbol_name : symbol_names)
285 assume_init_pointers_not_null,
286 object_factory_parameters,
287 pointer_type_selector,
288 string_refinement_enabled,
290 for(
const auto &new_symbol_name : new_symbols)
291 additional_symbols.insert(
id2string(new_symbol_name));
295 symbol_names.clear();
298 initialize_symbol.
value = std::move(code_block);
312 bool is_static = !function_type.
has_this();
315 bool has_correct_type = function_type.
return_type().
id() == ID_empty &&
316 parameters.
size() == 1 &&
317 parameters[0].type().full_eq(*string_array_type);
318 bool public_access = function_type.
get(ID_access) == ID_public;
319 return named_main && is_static && has_correct_type && public_access;
325 bool assume_init_pointers_not_null,
335 main_arguments.resize(parameters.size());
345 for(std::size_t param_number=0;
346 param_number<parameters.size();
355 bool is_this=(param_number==0) && parameters[param_number].get_this();
366 main_arguments[param_number] = result;
375 object_factory_parameters;
377 if(assume_init_pointers_not_null || is_this)
390 const auto alternatives =
393 if(alternatives.empty())
403 pointer_type_selector,
408 INVARIANT(!is_this,
"We cannot have different types for `this` here");
436 std::vector<codet> cases;
437 cases.reserve(alternatives.size());
438 for(
const auto &type : alternatives)
450 pointer_type_selector,
455 cases.push_back(init_code_for_type);
470 code_inputt{base_name, main_arguments[param_number],
function.location});
473 return make_pair(init_code, main_arguments);
486 init_code.
add(std::move(*return_value));
513 const std::vector<exprt> &arguments,
521 for(std::size_t param_number = 0; param_number < parameters.size();
531 p_symbol.
base_name, arguments[param_number],
function.location});
559 std::string error_message;
561 config.
main.value(), symbol_table, error_message);
563 if(main_symbol_id.
empty())
566 <<
"main symbol resolution failed: " << error_message <<
messaget::eom;
573 "resolve_friendly_method_name should return a symbol-table identifier");
580 if(main_class.
empty())
587 std::string entry_method =
607 bool assume_init_pointers_not_null,
608 bool assert_uncaught_exceptions,
611 bool string_refinement_enabled,
626 assert(symbol.
type.
id()==ID_code);
632 assert_uncaught_exceptions,
633 object_factory_parameters,
634 pointer_type_selector,
642 bool assert_uncaught_exceptions,
652 symbol_tablet::symbolst::const_iterator init_it=
655 if(init_it==symbol_table.
symbols.end())
665 init_code.
add(std::move(call_init));
687 return_symbol.
mode=ID_java;
693 symbol_table.
add(return_symbol);
699 exc_symbol.
mode=ID_java;
703 symbol_table.
add(exc_symbol);
712 const std::pair<code_blockt, std::vector<exprt>> main_arguments =
713 build_arguments(symbol, symbol_table);
714 init_code.
append(main_arguments.first);
715 call_main.
arguments() = main_arguments.second;
730 irept catch_type_list(ID_exception_list);
731 irept catch_target_list(ID_label);
733 call_block.
add(std::move(push_universal_handler));
736 call_block.
add(std::move(call_main));
740 call_block.
add(std::move(pop_handler));
741 init_code.
add(std::move(call_block));
748 init_code.
add(std::move(toplevel_catch));
749 init_code.
add(std::move(landingpad));
752 init_code.
add(std::move(after_catch));
759 if(assert_uncaught_exceptions)
762 init_code, exc_symbol, symbol.
location);
773 new_symbol.
mode=ID_java;
775 if(!symbol_table.
insert(std::move(new_symbol)).second)
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A codet representing sequential composition of program statements.
#define JAVA_CLASS_MODEL_SUFFIX
code_blockt generate_nondet_switch(const irep_idt &name_prefix, const alternate_casest &switch_cases, const typet &int_type, const irep_idt &mode, const source_locationt &source_location, symbol_table_baset &symbol_table)
Pick nondeterministically between imperative actions 'switch_cases'.
static code_blockt record_pointer_parameters(const symbolt &function, const std::vector< exprt > &arguments, const symbol_table_baset &symbol_table)
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
reference_typet java_reference_type(const typet &subtype)
void set_function(const irep_idt &function)
#define JAVA_ENTRY_POINT_RETURN_SYMBOL
bool is_java_string_literal_id(const irep_idt &id)
const class_typet & to_class_type(const typet &type)
Cast a typet to a class_typet.
main_function_resultt get_main_symbol(const symbol_table_baset &symbol_table, const irep_idt &main_class, message_handlert &message_handler)
Figures out the entry point of the code to verify.
typet type
Type of symbol.
irep_idt function_id
Function id, used as a prefix for identifiers of temporaries.
optionalt< std::string > main
A goto_instruction_codet representing the declaration of a local variable.
std::vector< parametert > parameterst
std::list< std::string > string_input_values
Force one of finitely many explicitly given input strings.
Base class for all expressions.
bool is_java_array_tag(const irep_idt &tag)
See above.
std::function< std::pair< code_blockt, std::vector< exprt > >(const symbolt &function, symbol_table_baset &symbol_table)> build_argumentst
irep_idt base_name
Base (non-scoped) name.
Pushes an exception handler, of the form: exception_tag1 -> label1 exception_tag2 -> label2 ....
A struct tag type, i.e., struct_typet with an identifier.
virtual std::set< struct_tag_typet > get_parameter_alternative_types(const irep_idt &function_name, const irep_idt ¶meter_name, const namespacet &ns) const
Get alternative types for a method parameter, e.g., based on the casts in the function body.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Internally generated symbol table entry.
Expression to hold a symbol (variable)
symbol_exprt get_or_create_string_literal_symbol(const java_string_literal_exprt &string_expr, symbol_table_baset &symbol_table, bool string_refinement_enabled)
Creates or gets an existing constant global symbol for a given string literal.
Pops an exception handler from the stack of active handlers (i.e.
bool has_suffix(const std::string &s, const std::string &suffix)
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
static codet record_exception(const symbolt &function, const symbol_table_baset &symbol_table)
bool get_is_constructor() const
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
const irep_idt & get(const irep_idt &name) const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
A goto_instruction_codet representing the declaration that an output of a particular description has ...
typet & type()
Return the type of the expression.
goto_instruction_codet representation of a function call statement.
static std::unordered_set< irep_idt > init_symbol(const symbolt &sym, code_blockt &code_block, symbol_table_baset &symbol_table, const source_locationt &source_location, bool assume_init_pointers_not_null, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, message_handlert &message_handler)
void set_class_identifier(struct_exprt &expr, const namespacet &ns, const struct_tag_typet &class_type)
If expr has its components filled in then sets the @class_identifier member of the struct.
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_tablet &symbol_table)
irep_idt mode
Language mode.
const irep_idt & get_base_name() const
irep_idt get_java_class_literal_initializer_signature()
Get the symbol name of java.lang.Class' initializer method.
static optionalt< codet > record_return_value(const symbolt &function, const symbol_table_baset &symbol_table)
The null pointer constant.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
void java_static_lifetime_init(symbol_table_baset &symbol_table, const source_locationt &source_location, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, message_handlert &message_handler)
Adds the body to __CPROVER_initialize.
codet representation of a goto statement.
codet representation of a label for branch targets.
#define PRECONDITION(CONDITION)
The symbol table base class interface.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
#define INITIALIZE_FUNCTION
irep_idt resolve_friendly_method_name(const std::string &friendly_name, const symbol_table_baset &symbol_table, std::string &error)
Resolves a user-friendly method name (like packagename.Class.method) into an internal name (like java...
exprt object_factory(const typet &type, const irep_idt base_name, code_blockt &init_code, symbol_table_baset &symbol_table, java_object_factory_parameterst parameters, lifetimet lifetime, const source_locationt &loc, const select_pointer_typet &pointer_type_selector, message_handlert &log)
Similar to gen_nondet_init below, but instead of allocating and non-deterministically initializing th...
bool is_non_null_library_global(const irep_idt &symbolid)
Check if a symbol is a well-known non-null global.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
bool is_java_main(const symbolt &function)
Checks whether the given symbol is a valid java main method i.e.
A codet representing an assignment in the program.
void gen_nondet_init(const exprt &expr, code_blockt &init_code, symbol_table_baset &symbol_table, const source_locationt &loc, bool skip_classid, lifetimet lifetime, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, update_in_placet update_in_place, message_handlert &log)
Initializes a primitive-typed or reference-typed object tree rooted at expr, allocating child objects...
const irep_idt & id() const
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
std::vector< exprt > operandst
void add(const codet &code)
irep_idt rounding_mode_identifier()
Return the identifier of the program symbol used to store the current rounding mode.
signedbv_typet java_int_type()
const parameterst & parameters() const
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
static constant_exprt constant_bool(bool val)
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)
nonstd::optional< T > optionalt
optionalt< typet > java_type_from_string(const std::string &src, const std::string &class_name_prefix)
Transforms a string representation of a Java type into an internal type representation thereof.
bool java_entry_point(symbol_table_baset &symbol_table, const irep_idt &main_class, message_handlert &message_handler, bool assume_init_pointers_not_null, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, const build_argumentst &build_arguments)
Given the symbol_table and the main_class to test, this function generates a new function __CPROVER__...
std::pair< code_blockt, std::vector< exprt > > java_build_arguments(const symbolt &function, symbol_table_baset &symbol_table, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, message_handlert &message_handler)
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...
size_t min_null_tree_depth
To force a certain depth of non-null objects.
A side_effect_exprt that returns a non-deterministically chosen value.
const irep_idt & get_label() const
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
static const symbolt * get_class_literal_initializer(const symbolt &symbol, const symbol_table_baset &symbol_table)
If symbol is a class literal, and an appropriate initializer method exists, return a pointer to its s...
exprt value
Initial value of symbol.
A codet representing a skip statement.
A statement that catches an exception, assigning the exception in flight to an expression (e....
void create_java_initialize(symbol_table_baset &symbol_table)
Adds __cprover_initialize to the symbol_table but does not generate code for it yet.
source_locationt location
Source code location of definition of symbol.
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const irep_idt & get_identifier() const
@ STATIC_GLOBAL
Allocate global objects with static lifetime.
static bool should_init_symbol(const symbolt &sym)
c_bool_typet java_boolean_type()
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
@ DYNAMIC
Allocate dynamic objects (using ALLOCATE)
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const typet & return_type() const
There are a large number of kinds of tree structured or tree-like data in CPROVER.
const java_class_typet & to_java_class_type(const typet &type)
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
const changesett & get_inserted() const
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
source_locationt & add_source_location()
static code_blockt java_record_outputs(const symbolt &function, const exprt::operandst &main_arguments, symbol_table_baset &symbol_table)
Mark return value, pointer type parameters and the exception as outputs.
const java_method_typet & to_java_method_type(const typet &type)
Semantic type conversion.
empty_typet java_void_type()
A constant literal expression.
bool generate_java_start_function(const symbolt &symbol, symbol_table_baset &symbol_table, message_handlert &message_handler, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, const build_argumentst &build_arguments)
Generate a _start function for a specific function.
A symbol table wrapper that records which entries have been updated/removed.
#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL
irep_idt name
The unique identifier.
bool get_bool(const irep_idt &name) const
An expression containing a side effect.
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
Data structure for representing an arbitrary statement in a program.