diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 6c5270d9d..eda8c2c24 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -1005,6 +1005,10 @@ module Procname = struct is_c_function name + let is_java_access_method pname = + match pname with Java java_pname -> Java.is_access_method java_pname | _ -> false + + let is_objc_method procname = match procname with ObjC_Cpp name -> ObjC_Cpp.is_objc_method name | _ -> false diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 4ad3e947b..1dda3515e 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -519,6 +519,8 @@ being the name of the struct, [None] means the parameter is of some other type. val parameter_of_name : t -> Name.t -> Parameter.t + val is_java_access_method : t -> bool + val is_objc_method : t -> bool (** Hash tables with proc names as keys. *) diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index 2dcb2ce5d..071227077 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -342,7 +342,7 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct let to_string {loc; proc_name; cost_opt} = match cost_opt with - | Some {post} -> + | Some {post} when not (Typ.Procname.is_java_access_method proc_name) -> let basic_operation_cost = CostDomain.get_operation_cost post in let degree_with_term = CostDomain.BasicCost.get_degree_with_term basic_operation_cost in let hum = @@ -367,7 +367,7 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct ; hum } in Some (Jsonbug_j.string_of_cost_item cost_item) - | None -> + | _ -> None end) diff --git a/infer/src/checkers/cost.ml b/infer/src/checkers/cost.ml index cec2d488d..ae61b5d4d 100644 --- a/infer/src/checkers/cost.ml +++ b/infer/src/checkers/cost.ml @@ -762,16 +762,18 @@ module Check = struct let check_and_report WorstCaseCost.{costs; reports} proc_desc summary = - CostDomain.CostKindMap.iter2 ReportConfig.as_map reports - ~f:(fun kind ReportConfig.{name; threshold} -> function - | ThresholdReports.Threshold _ -> - () - | ThresholdReports.ReportOn {location; cost} -> - report_threshold proc_desc summary ~name ~location ~cost - ~threshold:(Option.value_exn threshold) ~kind ) ; - CostDomain.CostKindMap.iter2 ReportConfig.as_map costs - ~f:(fun _kind ReportConfig.{name; top_and_bottom} cost -> - if top_and_bottom then report_top_and_bottom proc_desc summary ~name ~cost ) + let pname = Procdesc.get_proc_name proc_desc in + if not (Typ.Procname.is_java_access_method pname) then ( + CostDomain.CostKindMap.iter2 ReportConfig.as_map reports + ~f:(fun kind ReportConfig.{name; threshold} -> function + | ThresholdReports.Threshold _ -> + () + | ThresholdReports.ReportOn {location; cost} -> + report_threshold proc_desc summary ~name ~location ~cost + ~threshold:(Option.value_exn threshold) ~kind ) ; + CostDomain.CostKindMap.iter2 ReportConfig.as_map costs + ~f:(fun _kind ReportConfig.{name; top_and_bottom} cost -> + if top_and_bottom then report_top_and_bottom proc_desc summary ~name ~cost ) ) end type bound_map = BasicCost.t Node.IdMap.t diff --git a/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp b/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp index 526cdfd6a..5c0311264 100644 --- a/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp +++ b/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp @@ -1 +1 @@ -{"top":{"current":4,"previous":2},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":7,"previous":7},{"degree":100,"current":2,"previous":4},{"degree":101,"current":4,"previous":0},{"degree":200,"current":3,"previous":4}]} \ No newline at end of file +{"top":{"current":4,"previous":2},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":7,"previous":6},{"degree":100,"current":2,"previous":4},{"degree":101,"current":4,"previous":0},{"degree":200,"current":2,"previous":4}]} \ No newline at end of file diff --git a/infer/tests/build_systems/differential_of_costs_report/introduced.exp b/infer/tests/build_systems/differential_of_costs_report/introduced.exp index aa0261a6c..0ac3e1a94 100644 --- a/infer/tests/build_systems/differential_of_costs_report/introduced.exp +++ b/infer/tests/build_systems/differential_of_costs_report/introduced.exp @@ -1,5 +1,4 @@ PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample$1.toString():java.lang.String, 0, [Updated Cost is 16 + 13 ⋅ this.this$0.z + 5 ⋅ this.this$0.z × this.this$0.z (degree is 2),{this.this$0.z},call to void DiffExample.f8(int),call to int DiffExample.f4(int),Loop at line 57,{this.this$0.z},call to void DiffExample.f8(int),Loop at line 79] -PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.access$000(int):void, 0, [Updated Cost is 7 + 13 ⋅ x0 + 5 ⋅ x0 × x0 (degree is 2),{x0},call to void DiffExample.f8(int),call to int DiffExample.f4(int),Loop at line 57,{x0},call to void DiffExample.f8(int),Loop at line 79] INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop at line 38] PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Updated Cost is 6 + 5 ⋅ k (degree is 1),{k},Loop at line 57] PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Updated Cost is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort]