From e05fd1be67194c6539f26376c399bfa5e59b74ff Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Wed, 24 Mar 2021 03:04:18 -0700 Subject: [PATCH] [ConfigImpact] Ignore cheap functions like Math.ceil during the analysis Summary: This diff ignores java.lang.Math method calls since they are all cheap. Reviewed By: ezgicicek Differential Revision: D27267282 fbshipit-source-id: ad0a4ef4f --- infer/src/absint/PatternMatch.ml | 2 + infer/src/absint/PatternMatch.mli | 83 +++++++++++----------- infer/src/checkers/ConfigImpactAnalysis.ml | 10 +++ 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 3e32bdb20..180830a5c 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -121,6 +121,8 @@ module Java = struct let implements_list = implements "java.util.List" + let implements_math = implements "java.lang.Math" + let implements_xmob_utils class_name = implements ("com.moblica.common.xmob.utils." ^ class_name) let implements_pseudo_collection = diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index e715fcae0..7ef3b7e04 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -29,14 +29,20 @@ module Java : sig val implements : string -> Tenv.t -> string -> bool (** Check whether class implements a given Java class *) - val implements_arrays : Tenv.t -> string -> bool - (** Check whether class implements Java's Arrays *) + val implements_android : string -> Tenv.t -> string -> bool + (** Check whether class implements a class of Android *) - val implements_iterable : Tenv.t -> string -> bool - (** Check whether class implements Java's Iterable *) + val implements_androidx_map : Tenv.t -> string -> bool + (** Check whether class implements a AndroidX's Map *) - val implements_iterator : Tenv.t -> string -> bool - (** Check whether class implements Java's Iterator *) + val implements_app_activity : Tenv.t -> string -> bool + (** Check whether class implements a class of [android.app.Activity] *) + + val implements_app_fragment : Tenv.t -> string -> bool + (** Check whether class implements a class of [androidx.fragment.app.Fragment] *) + + val implements_arrays : Tenv.t -> string -> bool + (** Check whether class implements Java's Arrays *) val implements_collection : Tenv.t -> string -> bool (** Check whether class implements a Java's Collection *) @@ -44,17 +50,17 @@ module Java : sig val implements_collections : Tenv.t -> string -> bool (** Check whether class implements a Java's Collections *) - val implements_pseudo_collection : Tenv.t -> string -> bool - (** Check whether class implements a pseudo Collection with support for get() and size() methods *) - val implements_enumeration : Tenv.t -> string -> bool (** Check whether class implements a Java's Enumeration *) - val implements_jackson : string -> Tenv.t -> string -> bool - (** Check whether class implements a class from Jackson *) + val implements_google : string -> Tenv.t -> string -> bool + (** Check whether class implements a class of Google *) - val implements_org_json : string -> Tenv.t -> string -> bool - (** Check whether class implements a class from Json *) + val implements_graphql_story : Tenv.t -> string -> bool + (** Check whether class implements a class of [com.facebook.graphql.model.GraphQLStory] *) + + val implements_infer_annotation : string -> Tenv.t -> string -> bool + (** Check whether class implements a class of Infer annotation *) val implements_inject : string -> Tenv.t -> string -> bool (** Check whether class implements a Javax Inject *) @@ -62,23 +68,14 @@ module Java : sig val implements_io : string -> Tenv.t -> string -> bool (** Check whether class implements a Java IO *) - val implements_nio : string -> Tenv.t -> string -> bool - (** Check whether class implements a Java nio *) - - val implements_map : Tenv.t -> string -> bool - (** Check whether class implements a Java's Map *) - - val implements_androidx_map : Tenv.t -> string -> bool - (** Check whether class implements a AndroidX's Map *) - - val implements_set : Tenv.t -> string -> bool - (** Check whether class implements a Java's Set *) + val implements_iterable : Tenv.t -> string -> bool + (** Check whether class implements Java's Iterable *) - val implements_map_entry : Tenv.t -> string -> bool - (** Check whether class implements a Java's Map$Entry *) + val implements_iterator : Tenv.t -> string -> bool + (** Check whether class implements Java's Iterator *) - val implements_queue : Tenv.t -> string -> bool - (** Check whether class implements a Java's Queue *) + val implements_jackson : string -> Tenv.t -> string -> bool + (** Check whether class implements a class from Jackson *) val implements_lang : string -> Tenv.t -> string -> bool (** Check whether class implements a Java's lang *) @@ -86,27 +83,33 @@ module Java : sig val implements_list : Tenv.t -> string -> bool (** Check whether class implements a Java's list *) - val implements_google : string -> Tenv.t -> string -> bool - (** Check whether class implements a class of Google *) + val implements_map : Tenv.t -> string -> bool + (** Check whether class implements a Java's Map *) - val implements_android : string -> Tenv.t -> string -> bool - (** Check whether class implements a class of Android *) + val implements_map_entry : Tenv.t -> string -> bool + (** Check whether class implements a Java's Map$Entry *) - val implements_infer_annotation : string -> Tenv.t -> string -> bool - (** Check whether class implements a class of Infer annotation *) + val implements_math : Tenv.t -> string -> bool + (** Check whether class implements a Java's Math *) - val implements_app_activity : Tenv.t -> string -> bool - (** Check whether class implements a class of [android.app.Activity] *) + val implements_nio : string -> Tenv.t -> string -> bool + (** Check whether class implements a Java nio *) - val implements_app_fragment : Tenv.t -> string -> bool - (** Check whether class implements a class of [androidx.fragment.app.Fragment] *) + val implements_org_json : string -> Tenv.t -> string -> bool + (** Check whether class implements a class from Json *) - val implements_graphql_story : Tenv.t -> string -> bool - (** Check whether class implements a class of [com.facebook.graphql.model.GraphQLStory] *) + val implements_pseudo_collection : Tenv.t -> string -> bool + (** Check whether class implements a pseudo Collection with support for get() and size() methods *) val implements_psi_element : Tenv.t -> string -> bool (** Check whether class implements a class of [com.intellij.psi.PsiElement] *) + val implements_queue : Tenv.t -> string -> bool + (** Check whether class implements a Java's Queue *) + + val implements_set : Tenv.t -> string -> bool + (** Check whether class implements a Java's Set *) + val implements_sparse_float_array : Tenv.t -> string -> bool (** Check whether class implements a class of [com.facebook.litho.internal.SparseFloatArray] *) diff --git a/infer/src/checkers/ConfigImpactAnalysis.ml b/infer/src/checkers/ConfigImpactAnalysis.ml index 5bc05c9da..355e289ca 100644 --- a/infer/src/checkers/ConfigImpactAnalysis.ml +++ b/infer/src/checkers/ConfigImpactAnalysis.ml @@ -237,6 +237,14 @@ module TransferFunctions = struct && Procname.get_method pname |> String.equal "booleanValue" + let is_known_cheap_method = + let dispatch : (Tenv.t, unit, unit) ProcnameDispatcher.ProcName.dispatcher = + let open ProcnameDispatcher.ProcName in + make_dispatcher [+PatternMatch.Java.implements_math &::.*--> ()] + in + fun tenv pname -> dispatch tenv pname |> Option.is_some + + let exec_instr astate {InterproceduralAnalysis.tenv; analyze_dependency} _node instr = match (instr : Sil.instr) with | Load {id; e= Lvar pvar} -> @@ -246,6 +254,8 @@ module TransferFunctions = struct | Call ((ret, _), Const (Cfun callee), [(Var id, _)], _, _) when is_java_boolean_value_method callee -> Dom.boolean_value ret id astate + | Call (_, Const (Cfun callee), _, _, _) when is_known_cheap_method tenv callee -> + astate | Call ((ret, _), Const (Cfun callee), args, location, _) -> ( match FbGKInteraction.get_config_check tenv callee args with | Some (`Config config) ->