From 2351f767dcab5271dd3297f271fdc1fef002fcb2 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 27 Jan 2017 10:21:33 -0800 Subject: [PATCH] [cleanup] use pdesc_has_return_annot and friends instead of more cumbersome ways of looking up return annots Reviewed By: jeremydubreil Differential Revision: D4470062 fbshipit-source-id: 7acde20 --- infer/src/backend/interproc.ml | 9 +++------ infer/src/checkers/ThreadSafety.ml | 16 +++++----------- infer/src/checkers/annotations.mli | 4 ++++ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/infer/src/backend/interproc.ml b/infer/src/backend/interproc.ml index 03fd67c2b..fe10fd23e 100644 --- a/infer/src/backend/interproc.ml +++ b/infer/src/backend/interproc.ml @@ -1186,15 +1186,12 @@ let report_runtime_exceptions tenv pdesc summary = && String.equal (Procname.java_get_method pname_java) "main" | _ -> false) in - let is_annotated = - let proc_attributes = Specs.pdesc_resolve_attributes pdesc in - let annotated_signature = Annotations.get_annotated_signature proc_attributes in - let ret_annotation, _ = annotated_signature.Annotations.ret in - Annotations.ia_is_verify ret_annotation in + let is_annotated pdesc = + Annotations.pdesc_has_return_annot pdesc Annotations.ia_is_verify in let (exn_preconditions, all_post_exn) = exception_preconditions tenv pname summary in let should_report pre = - all_post_exn || is_main || is_annotated || is_unavoidable tenv pre in + all_post_exn || is_main || is_annotated pdesc || is_unavoidable tenv pre in let report (pre, runtime_exception) = if should_report pre then let pre_str = diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index d7c1e14f8..7ca22698d 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -408,18 +408,13 @@ let is_call_to_immutable_collection_method tenv = function | _ -> false -let is_annotated f_annot pdesc = - let annotated_signature = Annotations.get_annotated_signature (Procdesc.get_attributes pdesc) in - let ret_annotation, _ = annotated_signature.Annotations.ret in - f_annot ret_annotation - (* Methods in @ThreadConfined classes and methods annotated with @ThreadConfied are assumed to all run on the same thread. For the moment we won't warn on accesses resulting from use of such methods at all. In future we should account for races between these methods and methods from completely different classes that don't necessarily run on the same thread as the confined object. *) let is_thread_confined_method tenv pdesc = - is_annotated Annotations.ia_is_thread_confined pdesc || + Annotations.pdesc_return_annot_ends_with pdesc Annotations.thread_confined || PatternMatch.check_current_class_attributes Annotations.ia_is_thread_confined tenv (Procdesc.get_proc_name pdesc) @@ -428,7 +423,8 @@ let is_thread_confined_method tenv pdesc = let runs_on_ui_thread proc_desc = (* assume that methods annotated with @UiThread, @OnEvent, @OnBind, @OnMount, @OnUnbind, @OnUnmount always run on the UI thread *) - is_annotated + Annotations.pdesc_has_return_annot + proc_desc (fun annot -> Annotations.ia_is_ui_thread annot || Annotations.ia_is_on_bind annot || Annotations.ia_is_on_event annot || @@ -436,10 +432,8 @@ let runs_on_ui_thread proc_desc = Annotations.ia_is_on_unbind annot || Annotations.ia_is_on_unmount annot) - proc_desc - let is_assumed_thread_safe pdesc = - is_annotated Annotations.ia_is_assume_thread_safe pdesc + Annotations.pdesc_return_annot_ends_with pdesc Annotations.assume_thread_safe (* return true if we should compute a summary for the procedure. if this returns false, we won't analyze the procedure or report any warnings on it *) @@ -613,7 +607,7 @@ let process_results_table file_env tab = tenv pname; !found in - is_annotated Annotations.ia_is_thread_safe_method pdesc|| + Annotations.pdesc_return_annot_ends_with pdesc Annotations.thread_safe_method || overrides_thread_safe_method (Procdesc.get_proc_name pdesc) tenv in let should_report ((_, tenv, _, pdesc) as proc_env) = (should_report_on_all_procs || is_thread_safe_method pdesc tenv) diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 0d8182975..1e8bbc758 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -12,6 +12,7 @@ open! IStd (** Annotations. *) val any_thread : string +val assume_thread_safe : string val expensive : string val no_allocation : string val nullable : string @@ -21,6 +22,9 @@ val for_non_ui_thread : string val for_ui_thread : string val guarded_by : string val suppress_lint : string +val thread_confined : string +val thread_safe : string +val thread_safe_method : string val ui_thread : string val visibleForTesting : string