[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
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 73f3c5e0cd
commit 2351f767dc

@ -1186,15 +1186,12 @@ let report_runtime_exceptions tenv pdesc summary =
&& String.equal (Procname.java_get_method pname_java) "main" && String.equal (Procname.java_get_method pname_java) "main"
| _ -> | _ ->
false) in false) in
let is_annotated = let is_annotated pdesc =
let proc_attributes = Specs.pdesc_resolve_attributes pdesc in Annotations.pdesc_has_return_annot pdesc Annotations.ia_is_verify 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 (exn_preconditions, all_post_exn) = let (exn_preconditions, all_post_exn) =
exception_preconditions tenv pname summary in exception_preconditions tenv pname summary in
let should_report pre = 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) = let report (pre, runtime_exception) =
if should_report pre then if should_report pre then
let pre_str = let pre_str =

@ -408,18 +408,13 @@ let is_call_to_immutable_collection_method tenv = function
| _ -> | _ ->
false 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 (* 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 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 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 completely different classes that don't necessarily run on the same thread as the confined
object. *) object. *)
let is_thread_confined_method tenv pdesc = 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 PatternMatch.check_current_class_attributes
Annotations.ia_is_thread_confined tenv (Procdesc.get_proc_name pdesc) 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 = let runs_on_ui_thread proc_desc =
(* assume that methods annotated with @UiThread, @OnEvent, @OnBind, @OnMount, @OnUnbind, (* assume that methods annotated with @UiThread, @OnEvent, @OnBind, @OnMount, @OnUnbind,
@OnUnmount always run on the UI thread *) @OnUnmount always run on the UI thread *)
is_annotated Annotations.pdesc_has_return_annot
proc_desc
(fun annot -> Annotations.ia_is_ui_thread annot || (fun annot -> Annotations.ia_is_ui_thread annot ||
Annotations.ia_is_on_bind annot || Annotations.ia_is_on_bind annot ||
Annotations.ia_is_on_event 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_unbind annot ||
Annotations.ia_is_on_unmount annot) Annotations.ia_is_on_unmount annot)
proc_desc
let is_assumed_thread_safe pdesc = 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 (* 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 *) analyze the procedure or report any warnings on it *)
@ -613,7 +607,7 @@ let process_results_table file_env tab =
tenv tenv
pname; pname;
!found in !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 overrides_thread_safe_method (Procdesc.get_proc_name pdesc) tenv in
let should_report ((_, tenv, _, pdesc) as proc_env) = let should_report ((_, tenv, _, pdesc) as proc_env) =
(should_report_on_all_procs || is_thread_safe_method pdesc tenv) (should_report_on_all_procs || is_thread_safe_method pdesc tenv)

@ -12,6 +12,7 @@ open! IStd
(** Annotations. *) (** Annotations. *)
val any_thread : string val any_thread : string
val assume_thread_safe : string
val expensive : string val expensive : string
val no_allocation : string val no_allocation : string
val nullable : string val nullable : string
@ -21,6 +22,9 @@ val for_non_ui_thread : string
val for_ui_thread : string val for_ui_thread : string
val guarded_by : string val guarded_by : string
val suppress_lint : string val suppress_lint : string
val thread_confined : string
val thread_safe : string
val thread_safe_method : string
val ui_thread : string val ui_thread : string
val visibleForTesting : string val visibleForTesting : string

Loading…
Cancel
Save