From 62fa99ad3f31fde4543d93c26e9bb094b954e9b7 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 10 May 2018 11:10:26 -0700 Subject: [PATCH] Simplified example showing problem with arrays Reviewed By: ddino Differential Revision: D7910760 fbshipit-source-id: a79dca4 --- infer/src/checkers/cost.ml | 15 ++++---- .../java/performance/ArrayCost.java | 36 +++++++++---------- .../codetoanalyze/java/performance/issues.exp | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/infer/src/checkers/cost.ml b/infer/src/checkers/cost.ml index 950fc90b1..6ec55c45e 100644 --- a/infer/src/checkers/cost.ml +++ b/infer/src/checkers/cost.ml @@ -524,13 +524,13 @@ module TransferFunctionsWCET = struct match AnalyzerNodesBasicCost.extract_post instr_node_id invariant_map_cost with | Some node_map -> L.(debug Analysis Medium) - "@\n AnalyzerWCET] Final map for node: %a @\n" CFG.pp_id instr_node_id ; + "@\n [AnalyzerWCET] Final map for node: %a @\n" CFG.pp_id instr_node_id ; map_cost trees node_map | _ -> assert false in L.(debug Analysis Medium) - "@\n>>>AnalyzerWCET] Instr: %a Cost: %a@\n" (Sil.pp_instr Pp.text) instr BasicCost.pp + "@\n[>>>AnalyzerWCET] Instr: %a Cost: %a@\n" (Sil.pp_instr Pp.text) instr BasicCost.pp cost_node ; let astate' = let und_node = CFG.underlying_node node in @@ -597,10 +597,6 @@ let checker ({Callbacks.tenv; proc_desc} as callback_args) : Summary.t = control_dep_invariant_map in let constraints = StructuralConstraints.compute_structural_constraints node_cfg in - L.internal_error "@\n[COST ANALYSIS] PROCESSING MIN_TREE for PROCEDURE '%a' |CFG| = %i " - Typ.Procname.pp - (Procdesc.get_proc_name proc_desc) - (List.length (NodeCFG.nodes node_cfg)) ; let min_trees = MinTree.compute_trees_from_contraints bound_map node_cfg constraints in let trees_valuation = List.fold @@ -618,7 +614,12 @@ let checker ({Callbacks.tenv; proc_desc} as callback_args) : Summary.t = ~debug:true ~initial:initWCET with | Some (exit_cost, _) -> - L.internal_error " PROCEDURE COST = %a @\n" BasicCost.pp exit_cost ; + L.internal_error + "@\n[COST ANALYSIS] PROCESSING MIN_TREE for PROCEDURE '%a' |CFG| = %i FINAL COST = %a @\n" + Typ.Procname.pp + (Procdesc.get_proc_name proc_desc) + (List.length (NodeCFG.nodes node_cfg)) + BasicCost.pp exit_cost ; check_and_report_infinity exit_cost proc_desc summary ; Payload.update_summary {post= exit_cost} summary | None -> diff --git a/infer/tests/codetoanalyze/java/performance/ArrayCost.java b/infer/tests/codetoanalyze/java/performance/ArrayCost.java index ce7894830..81f68ebc7 100644 --- a/infer/tests/codetoanalyze/java/performance/ArrayCost.java +++ b/infer/tests/codetoanalyze/java/performance/ArrayCost.java @@ -8,32 +8,28 @@ */ public class ArrayCost { - private void ArrayCost_FP(int signum, int[] mag) { - if (mag.length > 0) { + private void ArrayCost_FP(int[] mag) { - int i = 0; + int i = 0; + int k = mag.length; - while (i < mag.length && mag[i] == 0) { - i++; - } - - } + while (i < k) { + i++; } + } - private static boolean isPowOfTwo_FP(int value) { - int ones = 0; - int v = value; - - for (int shifts = 0; shifts < 31 && ones <= 1; shifts++) { - if ((v & 1) == 1) { - ones++; - } + private static boolean isPowOfTwo_FP(int value) { + int ones = 0; + int v = value; - v >>= 1; - } + for (int shifts = 0; shifts < 31 && ones <= 1; shifts++) { + if ((v & 1) == 1) { + ones++; + } - return ones == 1; + v >>= 1; } - + return ones == 1; + } } diff --git a/infer/tests/codetoanalyze/java/performance/issues.exp b/infer/tests/codetoanalyze/java/performance/issues.exp index 15b5625b2..1686e353e 100644 --- a/infer/tests/codetoanalyze/java/performance/issues.exp +++ b/infer/tests/codetoanalyze/java/performance/issues.exp @@ -1,5 +1,5 @@ codetoanalyze/java/performance/ArrayCost.java, boolean ArrayCost.isPowOfTwo_FP(int), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, [] -codetoanalyze/java/performance/ArrayCost.java, void ArrayCost.ArrayCost_FP(int,int[]), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, [] +codetoanalyze/java/performance/ArrayCost.java, void ArrayCost.ArrayCost_FP(int[]), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, [] codetoanalyze/java/performance/JsonArray.java, void JsonArray.addStringEntry(String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, [] codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,JsonType), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, [] codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,Object), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []