Skip to content

Commit e34a845

Browse files
author
Daniel Kroening
authored
Merge pull request #387 from smowton/anonymous_locals_always_void_master
Treat all anonymous locals as void*
2 parents 15db047 + 043f02f commit e34a845

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,17 +733,21 @@ codet java_bytecode_convert_methodt::convert_instructions(
733733

734734
// do some type adjustment for the arguments,
735735
// as Java promotes arguments
736+
// Also cast pointers since intermediate locals
737+
// can be void*.
736738

737739
for(std::size_t i=0; i<parameters.size(); i++)
738740
{
739741
const typet &type=parameters[i].type();
740742
if(type==java_boolean_type() ||
741743
type==java_char_type() ||
742744
type==java_byte_type() ||
743-
type==java_short_type())
745+
type==java_short_type() ||
746+
type.id()==ID_pointer)
744747
{
745748
assert(i<call.arguments().size());
746-
call.arguments()[i].make_typecast(type);
749+
if(type!=call.arguments()[i].type())
750+
call.arguments()[i].make_typecast(type);
747751
}
748752
}
749753

@@ -833,12 +837,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
833837

834838
exprt var=variable(arg0, statement[0], i_it->address, INST_INDEX);
835839

836-
const bool is_array('a' == statement[0]);
840+
exprt toassign=op[0];
841+
if('a'==statement[0] && toassign.type()!=var.type())
842+
toassign=typecast_exprt(toassign, var.type());
837843

838-
if(is_array)
839-
var.type()=op[0].type();
840-
841-
c=code_assignt(var, op[0]);
844+
c=code_assignt(var, toassign);
842845
}
843846
else if(statement==patternt("?aload"))
844847
{
@@ -999,7 +1002,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
9991002
irep_idt number=to_constant_expr(arg0).get_value();
10001003
assert(op.size()==1 && results.empty());
10011004
code_ifthenelset code_branch;
1002-
const typecast_exprt lhs(op[0], pointer_typet());
1005+
const typecast_exprt lhs(op[0], pointer_typet(empty_typet()));
10031006
const exprt rhs(gen_zero(lhs.type()));
10041007
code_branch.cond()=binary_relation_exprt(lhs, ID_notequal, rhs);
10051008
code_branch.then_case()=code_gotot(label(number));

0 commit comments

Comments
 (0)