@@ -164,21 +164,18 @@ symbol_exprt java_bytecode_convert_methodt::tmp_variable(
164
164
// / from a bytecode at address `address` a value of type `type_char` stored in
165
165
// / the JVM's slot `arg`.
166
166
// / \param arg: The local variable slot
167
- // / \param type_char: The type of the value stored in the slot pointed by `arg`
167
+ // / \param type_char: The type of the value stored in the slot pointed to by
168
+ // / `arg`, this is only used in the case where a new unnamed local variable
169
+ // / is created
168
170
// / \param address: Bytecode address used to find a variable that the LVT
169
171
// / declares to be live and living in the slot pointed by `arg` for this
170
172
// / bytecode
171
- // / \param do_cast: Indicates whether we should return the original symbol_exprt
172
- // / or a typecast_exprt if the type of the symbol_exprt does not equal that
173
- // / represented by `type_char`
174
173
// / \return symbol_exprt or type-cast symbol_exprt
175
174
exprt java_bytecode_convert_methodt::variable (
176
175
const exprt &arg,
177
176
char type_char,
178
- size_t address,
179
- java_bytecode_convert_methodt::variable_cast_argumentt do_cast)
177
+ size_t address)
180
178
{
181
- typet t=java_type_from_char (type_char);
182
179
const std::size_t number_int =
183
180
numeric_cast_v<std::size_t >(to_constant_expr (arg));
184
181
variablest &var_list=variables[number_int];
@@ -187,24 +184,17 @@ exprt java_bytecode_convert_methodt::variable(
187
184
const variablet &var=
188
185
find_variable_for_slot (address, var_list);
189
186
190
- if (var.symbol_expr .get_identifier ().empty ())
191
- {
192
- // an unnamed local variable
193
- irep_idt base_name=" anonlocal::" +std::to_string (number_int)+type_char;
194
- irep_idt identifier=id2string (current_method)+" ::" +id2string (base_name);
195
-
196
- symbol_exprt result (identifier, t);
197
- result.set (ID_C_base_name, base_name);
198
- used_local_names.insert (result);
199
- return std::move (result);
200
- }
201
- else
202
- {
203
- exprt result=var.symbol_expr ;
204
- if (do_cast == CAST_AS_NEEDED)
205
- result = typecast_exprt::conditional_cast (result, t);
206
- return result;
207
- }
187
+ if (!var.symbol_expr .get_identifier ().empty ())
188
+ return var.symbol_expr ;
189
+
190
+ // an unnamed local variable
191
+ irep_idt base_name = " anonlocal::" + std::to_string (number_int) + type_char;
192
+ irep_idt identifier = id2string (current_method) + " ::" + id2string (base_name);
193
+
194
+ symbol_exprt result (identifier, java_type_from_char (type_char));
195
+ result.set (ID_C_base_name, base_name);
196
+ used_local_names.insert (result);
197
+ return std::move (result);
208
198
}
209
199
210
200
// / Returns the member type for a method, based on signature or descriptor
@@ -1346,8 +1336,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1346
1336
else if (bytecode == patternt (" ?load" ) || bytecode == patternt (" ?load_?" ))
1347
1337
{
1348
1338
// load a value from a local variable
1349
- results[0 ]=
1350
- variable (arg0, statement[0 ], i_it->address , CAST_AS_NEEDED);
1339
+ results[0 ] = convert_load (arg0, statement[0 ], i_it->address );
1351
1340
}
1352
1341
else if (bytecode == BC_ldc || bytecode == BC_ldc_w || bytecode == BC_ldc2_w)
1353
1342
{
@@ -2710,7 +2699,7 @@ code_blockt java_bytecode_convert_methodt::convert_iinc(
2710
2699
code_blockt block;
2711
2700
block.add_source_location () = location;
2712
2701
// search variable on stack
2713
- const exprt &locvar = variable (arg0, ' i' , address, NO_CAST );
2702
+ const exprt &locvar = variable (arg0, ' i' , address);
2714
2703
save_stack_entries (
2715
2704
" stack_iinc" ,
2716
2705
block,
@@ -2720,8 +2709,11 @@ code_blockt java_bytecode_convert_methodt::convert_iinc(
2720
2709
const exprt arg1_int_type =
2721
2710
typecast_exprt::conditional_cast (arg1, java_int_type ());
2722
2711
code_assignt code_assign (
2723
- variable (arg0, ' i' , address, NO_CAST),
2724
- plus_exprt (variable (arg0, ' i' , address, CAST_AS_NEEDED), arg1_int_type));
2712
+ variable (arg0, ' i' , address),
2713
+ plus_exprt (
2714
+ typecast_exprt::conditional_cast (
2715
+ variable (arg0, ' i' , address), java_int_type ()),
2716
+ arg1_int_type));
2725
2717
block.add (std::move (code_assign));
2726
2718
2727
2719
return block;
@@ -2826,7 +2818,7 @@ code_blockt java_bytecode_convert_methodt::convert_ret(
2826
2818
const method_offsett address)
2827
2819
{
2828
2820
code_blockt c;
2829
- auto retvar = variable (arg0, ' a' , address, NO_CAST );
2821
+ auto retvar = variable (arg0, ' a' , address);
2830
2822
for (size_t idx = 0 , idxlim = jsr_ret_targets.size (); idx != idxlim; ++idx)
2831
2823
{
2832
2824
irep_idt number = std::to_string (jsr_ret_targets[idx]);
@@ -2888,20 +2880,37 @@ exprt java_bytecode_convert_methodt::convert_aload(
2888
2880
return java_bytecode_promotion (dereference_exprt{data_plus_offset});
2889
2881
}
2890
2882
2883
+ exprt java_bytecode_convert_methodt::convert_load (
2884
+ const exprt &index,
2885
+ char type_char,
2886
+ size_t address)
2887
+ {
2888
+ const exprt var = variable (index, type_char, address);
2889
+ if (type_char == ' i' )
2890
+ {
2891
+ INVARIANT (
2892
+ can_cast_type<bitvector_typet>(var.type ()) &&
2893
+ type_try_dynamic_cast<bitvector_typet>(var.type ())->get_width () <= 32 ,
2894
+ " iload can be used for boolean, byte, short, int and char" );
2895
+ return typecast_exprt::conditional_cast (var, java_int_type ());
2896
+ }
2897
+ INVARIANT (
2898
+ (type_char == ' a' && can_cast_type<reference_typet>(var.type ())) ||
2899
+ var.type () == java_type_from_char (type_char),
2900
+ " Variable type must match [adflv]load return type" );
2901
+ return var;
2902
+ }
2903
+
2891
2904
code_blockt java_bytecode_convert_methodt::convert_store (
2892
2905
const irep_idt &statement,
2893
2906
const exprt &arg0,
2894
2907
const exprt::operandst &op,
2895
2908
const method_offsett address,
2896
2909
const source_locationt &location)
2897
2910
{
2898
- const exprt var = variable (arg0, statement[0 ], address, NO_CAST );
2911
+ const exprt var = variable (arg0, statement[0 ], address);
2899
2912
const irep_idt &var_name = to_symbol_expr (var).get_identifier ();
2900
2913
2901
- exprt toassign = op[0 ];
2902
- if (' a' == statement[0 ])
2903
- toassign = typecast_exprt::conditional_cast (toassign, var.type ());
2904
-
2905
2914
code_blockt block;
2906
2915
block.add_source_location () = location;
2907
2916
@@ -2911,7 +2920,9 @@ code_blockt java_bytecode_convert_methodt::convert_store(
2911
2920
bytecode_write_typet::VARIABLE,
2912
2921
var_name);
2913
2922
2914
- block.add (code_assignt{var, toassign}, location);
2923
+ block.add (
2924
+ code_assignt{var, typecast_exprt::conditional_cast (op[0 ], var.type ())},
2925
+ location);
2915
2926
return block;
2916
2927
}
2917
2928
0 commit comments