diff --git a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml index 7e098d19f..7a8ba2333 100644 --- a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml +++ b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml @@ -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) -> + 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 + copy_reachable_locs_from field_loc ~from_mem:clinit_mem ~to_mem:mem ) + in match field_typ.Typ.desc with - | Typ.Tptr ({desc= Tstruct _}, _) -> + | 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. Otherwise, it copies only the size of - static final array. *) - 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 ) + used as immutable, e.g., values of enum. *) + copy_from_class_init () + | Typ.Tptr ({desc= Tarray _}, _) -> + copy_from_class_init () | _ -> mem ) diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot b/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot index 4b60ff8cc..9f6ca4302 100644 --- a/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot +++ b/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot @@ -20,10 +20,7 @@ digraph callgraph { N2 -> N4 ; N2 -> N3 ; - N9 [ label = "void PrintStream.println(String)", flag = false ]; - N9 -> N2 ; - - N8 [ label = "void System.()", flag = false ]; + N8 [ label = "void PrintStream.println(String)", flag = false ]; N8 -> N2 ; N3 [ label = "void Test.complexityDecrease(int)", flag = true ]; diff --git a/infer/tests/codetoanalyze/java/performance/Array.java b/infer/tests/codetoanalyze/java/performance/Array.java index 3163beea6..de7b6edd6 100644 --- a/infer/tests/codetoanalyze/java/performance/Array.java +++ b/infer/tests/codetoanalyze/java/performance/Array.java @@ -91,4 +91,10 @@ public class Array { void toArray_linear(java.util.ArrayList 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++) {} + } }