[inferbo] Get static final array values from class initializer

Reviewed By: ezgicicek

Differential Revision: D20383941

fbshipit-source-id: 0539673f9
master
Sungkeun Cho 5 years ago committed by Facebook GitHub Bot
parent 2c96491e23
commit e35b26ae8e

@ -234,16 +234,18 @@ module TransferFunctions = struct
fun tenv get_summary exp mem ->
Option.value_map (Exp.get_java_class_initializer tenv exp) ~default:mem
~f:(fun (clinit_pname, pvar, fn, field_typ) ->
match field_typ.Typ.desc with
| Typ.Tptr ({desc= Tstruct _}, _) ->
(* It copies all of the reachable values when the contents of the field are commonly
used as immutable, e.g., values of enum. Otherwise, it copies only the size of
static final array. *)
let copy_from_class_init () =
Option.value_map (get_summary clinit_pname) ~default:mem ~f:(fun clinit_mem ->
let field_loc = Loc.append_field ~typ:field_typ (Loc.of_pvar pvar) ~fn in
if is_known_java_static_field fn then
copy_reachable_locs_from field_loc ~from_mem:clinit_mem ~to_mem:mem
else mem )
copy_reachable_locs_from field_loc ~from_mem:clinit_mem ~to_mem:mem )
in
match field_typ.Typ.desc with
| Typ.Tptr ({desc= Tstruct _}, _) when is_known_java_static_field fn ->
(* It copies all of the reachable values when the contents of the field are commonly
used as immutable, e.g., values of enum. *)
copy_from_class_init ()
| Typ.Tptr ({desc= Tarray _}, _) ->
copy_from_class_init ()
| _ ->
mem )

@ -20,10 +20,7 @@ digraph callgraph {
N2 -> N4 ;
N2 -> N3 ;
N9 [ label = "void PrintStream.println(String)", flag = false ];
N9 -> N2 ;
N8 [ label = "void System.<clinit>()", flag = false ];
N8 [ label = "void PrintStream.println(String)", flag = false ];
N8 -> N2 ;
N3 [ label = "void Test.complexityDecrease(int)", flag = true ];

@ -91,4 +91,10 @@ public class Array {
void toArray_linear(java.util.ArrayList<String> list) {
for (int i = 0; i < list.toArray().length; i++) {}
}
private static final String[] static_final_field = new String[] {"", ""};
void use_static_final_array_field_constant() {
for (int i = 0; i < static_final_field.length; i++) {}
}
}

Loading…
Cancel
Save