@@ -946,6 +946,38 @@ let instruction (context : JContext.t) pc instr : translation =
946946 let procname_string = Procname. to_string procname in
947947 Procdesc.Node. Stmt_node (Call procname_string)
948948 in
949+ let build_alloc var cn constructor_opt =
950+ let builtin_new = Exp. Const (Const. Cfun BuiltinDecl. __new) in
951+ let class_type = JTransType. get_class_type program tenv cn in
952+ let class_type_np = JTransType. get_class_type_no_pointer program tenv cn in
953+ let sizeof_exp =
954+ Exp. Sizeof {typ= class_type_np; nbytes= None ; dynamic_length= None ; subtype= Subtype. exact}
955+ in
956+ let args = [(sizeof_exp, class_type)] in
957+ let ret_id = Ident. create_fresh Ident. knormal in
958+ let new_instr = Sil. Call ((ret_id, class_type), builtin_new, args, loc, CallFlags. default) in
959+ let pvar = JContext. set_pvar context var class_type in
960+ let set_instr =
961+ Sil. Store {e1= Exp. Lvar pvar; root_typ= class_type; typ= class_type; e2= Exp. Var ret_id; loc}
962+ in
963+ match constructor_opt with
964+ | Some (constr_type_list , constr_arg_list ) ->
965+ let constr_ms = JBasics. make_ms JConfig. constructor_name constr_type_list None in
966+ let constr_procname, call_instrs =
967+ let ret_opt = Some (Exp. Var ret_id, class_type) in
968+ method_invocation context loc pc None cn constr_ms ret_opt constr_arg_list I_Special
969+ Procname.Java. Non_Static
970+ in
971+ let instrs = (new_instr :: call_instrs) @ [set_instr] in
972+ let node_kind = create_node_kind constr_procname in
973+ let node = create_node node_kind instrs in
974+ Instr node
975+ | None ->
976+ let instrs = [new_instr; set_instr] in
977+ let node_kind = Procdesc.Node. Stmt_node MethodBody in
978+ let node = create_node node_kind instrs in
979+ Instr node
980+ in
949981 try
950982 match (instr : JBir.instr ) with
951983 | AffectVar (var , expr ) ->
@@ -1063,33 +1095,11 @@ let instruction (context : JContext.t) pc instr : translation =
10631095 let node = create_node Procdesc.Node. throw_kind (instrs @ [sil_instr]) in
10641096 JContext. add_goto_jump context pc JContext. Exit ;
10651097 Instr node
1098+ | Alloc (var , cn ) ->
1099+ (* since Sawja 1.5.10 some allocation sites come without constructor calls *)
1100+ build_alloc var cn None
10661101 | New (var , cn , constr_type_list , constr_arg_list ) ->
1067- let builtin_new = Exp. Const (Const. Cfun BuiltinDecl. __new) in
1068- let class_type = JTransType. get_class_type program tenv cn in
1069- let class_type_np = JTransType. get_class_type_no_pointer program tenv cn in
1070- let sizeof_exp =
1071- Exp. Sizeof {typ= class_type_np; nbytes= None ; dynamic_length= None ; subtype= Subtype. exact}
1072- in
1073- let args = [(sizeof_exp, class_type)] in
1074- let ret_id = Ident. create_fresh Ident. knormal in
1075- let new_instr =
1076- Sil. Call ((ret_id, class_type), builtin_new, args, loc, CallFlags. default)
1077- in
1078- let constr_ms = JBasics. make_ms JConfig. constructor_name constr_type_list None in
1079- let constr_procname, call_instrs =
1080- let ret_opt = Some (Exp. Var ret_id, class_type) in
1081- method_invocation context loc pc None cn constr_ms ret_opt constr_arg_list I_Special
1082- Procname.Java. Non_Static
1083- in
1084- let pvar = JContext. set_pvar context var class_type in
1085- let set_instr =
1086- Sil. Store
1087- {e1= Exp. Lvar pvar; root_typ= class_type; typ= class_type; e2= Exp. Var ret_id; loc}
1088- in
1089- let instrs = (new_instr :: call_instrs) @ [set_instr] in
1090- let node_kind = create_node_kind constr_procname in
1091- let node = create_node node_kind instrs in
1092- Instr node
1102+ build_alloc var cn (Some (constr_type_list, constr_arg_list))
10931103 | NewArray (var , vt , expr_list ) ->
10941104 let builtin_new_array = Exp. Const (Const. Cfun BuiltinDecl. __new_array) in
10951105 let content_type = JTransType. value_type program tenv vt in
0 commit comments