Skip to content

Commit 822db22

Browse files
author
Daniel Kroening
committed
fixes for Java virtual method calls
1 parent c66d099 commit 822db22

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ bool cbmc_parse_optionst::process_goto_program(
862862
symbol_table, get_message_handler(), goto_functions);
863863

864864
// remove function pointers
865-
status() << "Removal of Function Pointers Virtual Functions" << eom;
865+
status() << "Removal of function pointers and virtual functions" << eom;
866866
remove_function_pointers(symbol_table, goto_functions,
867867
cmdline.isset("pointer-check"));
868868
remove_virtual_functions(symbol_table, goto_functions);

src/java_bytecode/java_bytecode_convert.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,45 +742,40 @@ codet java_bytecode_convertt::convert_instructions(
742742
// info for that type, and are instances of java.lang.Class
743743
assert(!call.arguments().empty());
744744

745-
exprt this_arg=call.arguments().front();
745+
exprt &this_arg=call.arguments().front();
746746

747747
if(this_arg.id()==ID_type)
748748
{
749749
irep_idt class_id=this_arg.type().get(ID_identifier);
750750
symbol_typet java_lang_Class("java::java.lang.Class");
751-
symbol_exprt symbol_expr("java::"+id2string(class_id)+"@class_model", java_lang_Class);
751+
symbol_exprt symbol_expr(id2string(class_id)+"@class_model", java_lang_Class);
752752
address_of_exprt address_of_expr(symbol_expr);
753753
this_arg=address_of_expr;
754754
}
755755

756756
assert(this_arg.type().id()==ID_pointer);
757-
758-
std::cout << "F: " << arg0.pretty() << "\n";
759757
}
760758

761759
const typet &return_type=code_type.return_type();
762760

763-
if(ID_empty != return_type.id())
761+
if(return_type.id()!=ID_empty)
764762
{
765-
call.lhs() = tmp_variable(return_type);
763+
call.lhs()=tmp_variable(return_type);
766764
results.resize(1);
767-
results[0] = call.lhs();
765+
results[0]=call.lhs();
768766
}
769767

770768
if(is_virtual)
771769
{
770+
assert(use_this);
772771
assert(!call.arguments().empty());
773772
const exprt &this_arg=call.arguments().front();
774773

775-
#if 0
776-
call.function()=make_vtable_function(arg0, this_arg);
777-
#else
778774
call.function()=make_virtual_function(
779775
to_symbol_expr(arg0), this_arg);
780-
#endif
781776
}
782777
else
783-
call.function() = arg0;
778+
call.function()=arg0;
784779

785780
call.function().add_source_location()=i_it->source_location;
786781
c = call;

src/solvers/flattening/boolbv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ class boolbvt:public arrayst
243243

244244
typedef std::vector<std::size_t> offset_mapt;
245245
void build_offset_map(const struct_typet &src, offset_mapt &dest);
246+
247+
// strings
248+
numbering<irep_idt> string_numbering;
246249
};
247250

248251
#endif

src/solvers/flattening/boolbv_constant.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ void boolbvt::convert_constant(const constant_exprt &expr, bvt &bv)
5151

5252
return;
5353
}
54+
else if(expr_type.id()==ID_string)
55+
{
56+
// we use the numbering for strings
57+
std::size_t number=string_numbering(expr.get_value());
58+
bv=bv_utils.build_constant(number, bv.size());
59+
return;
60+
}
5461
else if(expr_type.id()==ID_range)
5562
{
5663
mp_integer from=to_range_type(expr_type).get_from();

src/solvers/flattening/boolbv_get.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/arith_tools.h>
1212
#include <util/std_expr.h>
1313
#include <util/threeval.h>
14+
#include <util/std_types.h>
1415

1516
#include "boolbv.h"
1617
#include "boolbv_type.h"
@@ -260,6 +261,17 @@ exprt boolbvt::bv_get_rec(
260261
switch(bvtype)
261262
{
262263
case IS_UNKNOWN:
264+
if(type.id()==ID_string)
265+
{
266+
mp_integer int_value=binary2integer(value, false);
267+
irep_idt s;
268+
if(int_value>=string_numbering.size())
269+
s=irep_idt();
270+
else
271+
s=string_numbering[int_value.to_long()];
272+
273+
return constant_exprt(s, type);
274+
}
263275
break;
264276

265277
case IS_RANGE:

src/solvers/flattening/boolbv_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void boolbvt::convert_struct(const struct_exprt &expr, bvt &bv)
3535
throw "struct: wrong number of arguments";
3636

3737
bv.resize(width);
38-
38+
3939
std::size_t offset=0, i=0;
4040

4141
for(struct_typet::componentst::const_iterator

src/solvers/flattening/boolbv_width.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
247247
{
248248
entry.total_width=to_c_bit_field_type(type).get_width();
249249
}
250+
else if(type_id==ID_string)
251+
entry.total_width=32;
250252

251253
return entry;
252254
}

src/util/pointer_offset_size.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mp_integer pointer_offset_bits(
224224
}
225225
else if(type.id()==ID_string)
226226
{
227-
return config.ansi_c.int_width;
227+
return 32;
228228
}
229229
else
230230
return mp_integer(-1);
@@ -486,7 +486,7 @@ exprt size_of_expr(
486486
else if(type.id()==ID_string)
487487
{
488488
return from_integer(
489-
config.ansi_c.int_width, signedbv_typet(config.ansi_c.pointer_width));
489+
32/8, signedbv_typet(config.ansi_c.pointer_width));
490490
}
491491
else
492492
return nil_exprt();

0 commit comments

Comments
 (0)