[infer][java] remove the hack around virtual calls on arrays

Summary:
This approach was requiring the `InferArray` class to always be part of the classpath, and the only benefit was to preserve the length of the arrays, when known, on calls to `clone()` method. However, adding it to the models would create circular dependencies between the models, the builtins and the tests.

The code is now simpler and we can more aggressively fail when classes that are supposed to be found from the classpath are not found.

Reviewed By: sblackshear

Differential Revision: D5703173

fbshipit-source-id: 3e6cea5
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 5ead13a225
commit 1d8d6e3ceb

@ -1,47 +0,0 @@
/*
* Copyright (c) 2009 - 2013 Monoidics ltd.
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.infer.builtins;
public class InferArray {
public static Object[] clone(Object[] arr) {
return new Object[arr.length];
}
public static int[] clone(int[] arr) {
return new int[arr.length];
}
public static short[] clone(short[] arr) {
return new short[arr.length];
}
public static long[] clone(long[] arr) {
return new long[arr.length];
}
public static boolean[] clone(boolean[] arr) {
return new boolean[arr.length];
}
public static char[] clone(char[] arr) {
return new char[arr.length];
}
public static float[] clone(float[] arr) {
return new float[arr.length];
}
public static double[] clone(double[] arr) {
return new double[arr.length];
}
}

@ -17,8 +17,6 @@ let builtins_package = "com.facebook.infer.builtins"
let infer_builtins_cl = builtins_package ^ ".InferBuiltins" let infer_builtins_cl = builtins_package ^ ".InferBuiltins"
let infer_array_cl = builtins_package ^ ".InferArray"
let infer_undefined_cl = builtins_package ^ ".InferUndefined" let infer_undefined_cl = builtins_package ^ ".InferUndefined"
let obj_type = JBasics.TObject (JBasics.TClass JBasics.java_lang_object) let obj_type = JBasics.TObject (JBasics.TClass JBasics.java_lang_object)

@ -65,8 +65,6 @@ val field_st : Mangled.t
val infer_builtins_cl : string val infer_builtins_cl : string
val infer_array_cl : string
val npe_cl : string val npe_cl : string
val out_of_bound_cl : string val out_of_bound_cl : string

@ -64,29 +64,6 @@ let get_location source_file impl pc =
in in
{Location.line= line_number; col= -1; file= source_file} {Location.line= line_number; col= -1; file= source_file}
let get_undefined_method_call ovt =
let get_undefined_method ovt =
match ovt with
| None
-> JConfig.void ^ "_undefined"
| Some vt ->
match vt with
| JBasics.TBasic bt
-> JTransType.string_of_basic_type bt ^ "_undefined"
| JBasics.TObject ot ->
match ot with
| JBasics.TArray _
-> assert false
| JBasics.TClass cn
-> if String.equal (JBasics.cn_name cn) JConfig.string_cl then "string_undefined"
else if JBasics.cn_equal cn JBasics.java_lang_object then "object_undefined"
else assert false
in
let undef_cn = JBasics.make_cn JConfig.infer_undefined_cl in
let undef_name = get_undefined_method ovt in
let undef_ms = JBasics.make_ms undef_name [] ovt in
(undef_cn, undef_ms)
let retrieve_fieldname fieldname = let retrieve_fieldname fieldname =
try try
let subs = Str.split (Str.regexp (Str.quote ".")) (Typ.Fieldname.to_string fieldname) in let subs = Str.split (Str.regexp (Str.quote ".")) (Typ.Fieldname.to_string fieldname) in
@ -706,16 +683,6 @@ type translation =
| Prune of Procdesc.Node.t * Procdesc.Node.t | Prune of Procdesc.Node.t * Procdesc.Node.t
| Loop of Procdesc.Node.t * Procdesc.Node.t * Procdesc.Node.t | Loop of Procdesc.Node.t * Procdesc.Node.t * Procdesc.Node.t
let instruction_array_call ms obj_type obj args var_opt =
if is_clone ms then
let cn = JBasics.make_cn JConfig.infer_array_cl in
let vt = JBasics.TObject obj_type in
let ms = JBasics.make_ms JConfig.clone_name [vt] (Some vt) in
JBir.InvokeStatic (var_opt, cn, ms, obj :: args)
else
let undef_cn, undef_ms = get_undefined_method_call (JBasics.ms_rtype ms) in
JBir.InvokeStatic (var_opt, undef_cn, undef_ms, [])
let is_this expr = let is_this expr =
match expr with match expr with
| JBir.Var (_, var) -> ( | JBir.Var (_, var) -> (
@ -734,7 +701,7 @@ let assume_not_null loc sil_expr =
let call_args = [(not_null_expr, Typ.mk (Tint Typ.IBool))] in let call_args = [(not_null_expr, Typ.mk (Tint Typ.IBool))] in
Sil.Call (None, builtin_infer_assume, call_args, loc, assume_call_flag) Sil.Call (None, builtin_infer_assume, call_args, loc, assume_call_flag)
let rec instruction (context: JContext.t) pc instr : translation = let instruction (context: JContext.t) pc instr : translation =
let tenv = JContext.get_tenv context in let tenv = JContext.get_tenv context in
let cg = JContext.get_cg context in let cg = JContext.get_cg context in
let program = context.program in let program = context.program in
@ -942,13 +909,15 @@ let rec instruction (context: JContext.t) pc instr : translation =
Instr call_node Instr call_node
in in
match call_kind with match call_kind with
| JBir.VirtualCall obj_type -> ( | JBir.VirtualCall obj_type
match obj_type with -> let cn =
| JBasics.TClass cn match obj_type with
-> trans_virtual_call cn I_Virtual | JBasics.TClass cn
| JBasics.TArray _ -> cn
-> let instr = instruction_array_call ms obj_type obj args var_opt in | JBasics.TArray _
instruction context pc instr ) -> JBasics.java_lang_object
in
trans_virtual_call cn I_Virtual
| JBir.InterfaceCall cn | JBir.InterfaceCall cn
-> trans_virtual_call cn I_Interface ) -> trans_virtual_call cn I_Interface )
| JBir.InvokeNonVirtual (var_opt, obj, cn, ms, args) | JBir.InvokeNonVirtual (var_opt, obj, cn, ms, args)

Loading…
Cancel
Save