From 0a8919166fae43683cee94e9856ed40db21e1617 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Mon, 4 Nov 2019 01:22:26 -0800 Subject: [PATCH] [inferbo] Add a model: Object.clone Reviewed By: ezgicicek Differential Revision: D18272339 fbshipit-source-id: 6a84a1ac7 --- infer/src/bufferoverrun/bufferOverrunModels.ml | 12 +++++++++++- .../codetoanalyze/java/performance/Cost_test.java | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/infer/src/bufferoverrun/bufferOverrunModels.ml b/infer/src/bufferoverrun/bufferOverrunModels.ml index da41cd111..cc36e9b28 100644 --- a/infer/src/bufferoverrun/bufferOverrunModels.ml +++ b/infer/src/bufferoverrun/bufferOverrunModels.ml @@ -1155,6 +1155,15 @@ module ByteBuffer = struct {exec; check= no_check} end +module Object = struct + let clone exp = + let exec {integer_type_widths} ~ret:(ret_id, _) mem = + let v = Sem.eval integer_type_widths exp mem in + model_by_value v ret_id mem + in + {exec; check= no_check} +end + module Call = struct let dispatch : (Tenv.t, model) ProcnameDispatcher.Call.dispatcher = let open ProcnameDispatcher.Call in @@ -1394,5 +1403,6 @@ module Call = struct &:: "getShort" <>$ capt_exp $--> ByteBuffer.get_int ; +PatternMatch.implements_nio "ByteBuffer" &:: "getInt" <>$ capt_exp $--> ByteBuffer.get_int ; +PatternMatch.implements_nio "ByteBuffer" - &:: "getLong" <>$ capt_exp $--> ByteBuffer.get_int ] + &:: "getLong" <>$ capt_exp $--> ByteBuffer.get_int + ; -"java.lang.Object" &:: "clone" <>$ capt_exp $--> Object.clone ] end diff --git a/infer/tests/codetoanalyze/java/performance/Cost_test.java b/infer/tests/codetoanalyze/java/performance/Cost_test.java index aa8a9339f..2fdd634e4 100644 --- a/infer/tests/codetoanalyze/java/performance/Cost_test.java +++ b/infer/tests/codetoanalyze/java/performance/Cost_test.java @@ -203,3 +203,13 @@ public class Cost_test { for (int i = 0; i < get_global(); i++) {} } } + +class CloneTest { + int i; + + void clone_test_constant() throws CloneNotSupportedException { + this.i = 10; + CloneTest o = (CloneTest) this.clone(); + for (int i = 0; i < o.i; i++) {} + } +}