void java_internal_additions(symbol_tablet &dest) { // add __CPROVER_rounding_mode { symbolt symbol; symbol.base_name="__CPROVER_rounding_mode"; symbol.name=CPROVER_PREFIX "rounding_mode"; symbol.type=signed_int_type(); symbol.mode=ID_C; symbol.is_lvalue=true; symbol.is_state_var=true; symbol.is_thread_local=true; dest.add(symbol); } // add __CPROVER_malloc_object { symbolt symbol; symbol.base_name="__CPROVER_malloc_object"; symbol.name=CPROVER_PREFIX "malloc_object"; symbol.type=pointer_type(empty_typet()); symbol.mode=ID_C; symbol.is_lvalue=true; symbol.is_state_var=true; symbol.is_thread_local=true; dest.add(symbol); } }
/// Causes an invariant failure dependent on first argument value. /// One ignored argument is accepted to conform with the test.pl script, /// which would be the input source file for other cbmc driver programs. /// Returns 1 on unexpected arguments. int main(int argc, char** argv) { if(argc!=3) return 1; std::string arg=argv[1]; if(arg=="structured") INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="string") INVARIANT(false, "Test invariant failure"); else if(arg=="precondition-structured") PRECONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="precondition-string") PRECONDITION(false); else if(arg=="postcondition-structured") POSTCONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="postcondition-string") POSTCONDITION(false); else if(arg=="check-return-structured") CHECK_RETURN_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="check-return-string") CHECK_RETURN(false); else if(arg=="unreachable-structured") UNREACHABLE_STRUCTURED(structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="unreachable-string") UNREACHABLE; else if(arg=="data-invariant-structured") DATA_INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="data-invariant-string") DATA_INVARIANT(false, "Test invariant failure"); else if(arg=="irep") INVARIANT_WITH_IREP(false, "error with irep", pointer_type(void_typet())); else return 1; }
/// Turns union.member into *((T *)(&union)), where T is the type of the member. /// This is semantics-preserving for unions, but requires some elaboration in /// case the union member is an array. void translate_union_member(exprt &dest, const namespacet &ns) { #if 0 if(dest.id()==ID_member) { // TODO } address_of_exprt address_of_expr(member_expr.struct_op()); pointer_typet pointer_type(member_expr.type()); typecast_exprt typecast_expr(address_of_expr, pointer_type); return dereference_exprt(typecast_expr, member_expr.type()); #endif }
static pointer_type make_ptr() {return pointer_type(new ModifierSet());}
static pointer_type make_ptr(const bfc::string_ptr& name) {return pointer_type(new Method(name));}
void cpp_typecheckt::do_virtual_table(const symbolt &symbol) { assert(symbol.type.id()==ID_struct); // builds virtual-table value maps: (class x virtual_name x value) std::map<irep_idt, std::map<irep_idt,exprt> > vt_value_maps; const struct_typet &struct_type = to_struct_type(symbol.type); for(unsigned i = 0; i < struct_type.components().size(); i++) { const struct_typet::componentt& compo = struct_type.components()[i]; if(!compo.get_bool("is_virtual")) continue; const code_typet& code_type = to_code_type(compo.type()); assert(code_type.arguments().size() > 0); const pointer_typet& pointer_type = static_cast<const pointer_typet&>(code_type.arguments()[0].type()); irep_idt class_id = pointer_type.subtype().get("identifier"); std::map<irep_idt,exprt>& value_map = vt_value_maps[class_id]; exprt e = symbol_exprt(compo.get_name(),code_type); if(compo.get_bool("is_pure_virtual")) { pointer_typet pointer_type(code_type); e = gen_zero(pointer_type); assert(e.is_not_nil()); value_map[compo.get("virtual_name")] = e; } else { address_of_exprt address(e); value_map[compo.get("virtual_name")] = address; } } // create virtual-table symbol variables for(std::map<irep_idt, std::map<irep_idt,exprt> >::const_iterator cit = vt_value_maps.begin(); cit != vt_value_maps.end(); cit++) { const std::map<irep_idt,exprt>& value_map = cit->second; const symbolt& late_cast_symb = namespacet(symbol_table).lookup(cit->first); const symbolt& vt_symb_type = namespacet(symbol_table).lookup("virtual_table::"+id2string(late_cast_symb.name)); symbolt vt_symb_var; vt_symb_var.name= id2string(vt_symb_type.name) + "@"+ id2string(symbol.name); vt_symb_var.base_name= id2string(vt_symb_type.base_name) + "@" + id2string(symbol.base_name); vt_symb_var.mode=ID_cpp; vt_symb_var.module=module; vt_symb_var.location=vt_symb_type.location; vt_symb_var.type = symbol_typet(vt_symb_type.name); vt_symb_var.is_lvalue = true; vt_symb_var.is_static_lifetime = true; // do the values const struct_typet &vt_type = to_struct_type(vt_symb_type.type); exprt values(ID_struct, symbol_typet(vt_symb_type.name)); for(unsigned i=0; i < vt_type.components().size(); i++) { const struct_typet::componentt& compo = vt_type.components()[i]; std::map<irep_idt,exprt>::const_iterator cit2 = value_map.find( compo.get("base_name")); assert(cit2 != value_map.end()); const exprt& value = cit2->second; assert(value.type() == compo.type()); values.operands().push_back(value); } vt_symb_var.value = values; bool failed = symbol_table.move(vt_symb_var); assert(!failed); } }
static pointer_type make_ptr() {return pointer_type(new ImportList());}
void goto_convertt::do_scanf( const exprt &lhs, const exprt &function, const exprt::operandst &arguments, goto_programt &dest) { const irep_idt &f_id=function.get(ID_identifier); if(f_id==CPROVER_PREFIX "scanf") { if(arguments.size()<1) { err_location(function); error() << "scanf takes at least one argument" << eom; throw 0; } irep_idt format_string; if(!get_string_constant(arguments[0], format_string)) { // use our model format_token_listt token_list=parse_format_string(id2string(format_string)); std::size_t argument_number=1; for(const auto & t : token_list) { typet type=get_type(t); if(type.is_not_nil()) { if(argument_number<arguments.size()) { exprt ptr= typecast_exprt(arguments[argument_number], pointer_type(type)); argument_number++; // make it nondet for now exprt lhs=dereference_exprt(ptr, type); exprt rhs=side_effect_expr_nondett(type); code_assignt assign(lhs, rhs); assign.add_source_location()=function.source_location(); copy(assign, ASSIGN, dest); } } } } else { // we'll just do nothing code_function_callt function_call; function_call.lhs()=lhs; function_call.function()=function; function_call.arguments()=arguments; function_call.add_source_location()=function.source_location(); copy(function_call, FUNCTION_CALL, dest); } } else assert(false); }
static constexpr pointer_type NextByte(pointer_type p, int delta) { return pointer_type((uint8_t *)p + delta); }
static pointer_type make_ptr() {return pointer_type(new ArgumentList());}
static pointer_type make_ptr(const bfc::string_ptr& name) {return pointer_type(new Argument(name));}
typet get_type(const format_tokent &token) { switch(token.type) { case format_tokent::INT: switch(token.length_modifier) { case format_tokent::LEN_h: if(token.representation==format_tokent::SIGNED_DEC) return signed_char_type(); else return unsigned_char_type(); case format_tokent::LEN_hh: if(token.representation==format_tokent::SIGNED_DEC) return signed_short_int_type(); else return unsigned_short_int_type(); case format_tokent::LEN_l: if(token.representation==format_tokent::SIGNED_DEC) return signed_long_int_type(); else return unsigned_long_int_type(); case format_tokent::LEN_ll: if(token.representation==format_tokent::SIGNED_DEC) return signed_long_long_int_type(); else return unsigned_long_long_int_type(); default: if(token.representation==format_tokent::SIGNED_DEC) return signed_int_type(); else return unsigned_int_type(); } case format_tokent::FLOAT: switch(token.length_modifier) { case format_tokent::LEN_l: return double_type(); case format_tokent::LEN_L: return long_double_type(); default: return float_type(); } case format_tokent::CHAR: switch(token.length_modifier) { case format_tokent::LEN_l: return wchar_t_type(); default: return char_type(); } case format_tokent::POINTER: return pointer_type(void_type()); case format_tokent::STRING: switch(token.length_modifier) { case format_tokent::LEN_l: return array_typet(wchar_t_type(), nil_exprt()); default: return array_typet(char_type(), nil_exprt()); } default: return nil_typet(); } }