Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Method Annotation Support #1669

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .inferconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"source_contains": "_SHOULD_BE_SKIPPED_"
}
]
}
}
3 changes: 2 additions & 1 deletion infer/src/atd/pulse_config.atd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ type argument_constraint = { index: int; type_matches: string list }

type matcher = {
(* exactly one of procedure or procedure_regex or allocation must be specified, or else
class_name and method_names must be specified, or else overrides_of_class_with_annotation *)
class_name and method_names must be specified, or else overrides_of_class_with_annotation/method_with_annotation *)
?procedure: string option;
?procedure_regex: string option;
?class_names: string list option;
?method_names: string list option;
?overrides_of_class_with_annotation: string option;
?method_with_annotation: string option;
?allocation: string option;
~argument_constraints: argument_constraint list;
~match_objc_blocks <ocaml default="false">: bool; (** whether this matcher identifies Objective-C blocks or regular procedures *)
Expand Down
21 changes: 20 additions & 1 deletion infer/src/pulse/PulseTaintOperations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type procedure_matcher =
| ProcedureNameRegex of {name_regex: Str.regexp}
| ClassAndMethodNames of {class_names: string list; method_names: string list}
| OverridesOfClassWithAnnotation of {annotation: string}
| MethodWithAnnotation of {annotation: string}
| Allocation of {class_name: string}

type matcher =
Expand Down Expand Up @@ -124,34 +125,47 @@ let matcher_of_config ~default_taint_target ~option_name matchers =
; class_names= None
; method_names= None
; overrides_of_class_with_annotation= None
; method_with_annotation= None
; allocation= None } ->
ProcedureName {name}
| { procedure= None
; procedure_regex= Some name_regex
; class_names= None
; method_names= None
; overrides_of_class_with_annotation= None
; method_with_annotation= None
; allocation= None } ->
ProcedureNameRegex {name_regex= Str.regexp name_regex}
| { procedure= None
; procedure_regex= None
; class_names= Some class_names
; method_names= Some method_names
; overrides_of_class_with_annotation= None
; method_with_annotation= None
; allocation= None } ->
ClassAndMethodNames {class_names; method_names}
| { procedure= None
; procedure_regex= None
; class_names= None
; method_names= None
; overrides_of_class_with_annotation= Some annotation
; method_with_annotation= None
; allocation= None } ->
OverridesOfClassWithAnnotation {annotation}
| { procedure= None
; procedure_regex= None
; class_names= None
; method_names= None
; overrides_of_class_with_annotation= None
; method_with_annotation= Some annotation
; allocation= None } ->
MethodWithAnnotation {annotation}
| { procedure= None
; procedure_regex= None
; class_names= None
; method_names= None
; overrides_of_class_with_annotation= None
; method_with_annotation= None
; allocation= Some class_name } ->
Allocation {class_name}
| _ ->
Expand All @@ -160,7 +174,8 @@ let matcher_of_config ~default_taint_target ~option_name matchers =
\"procedure_regex\", \"allocation\" must be provided, or else \"class_names\" and \
\"method_names\" must be provided, or else \"overrides_of_class_with_annotation\", \
but got \"procedure\": %a, \"procedure_regex\": %a, \"class_names\": %a, \
\"method_names\": %a, \"overrides_of_class_with_annotation\": %a, \"allocation\": \
\"method_names\": %a, \"overrides_of_class_with_annotation\": %a,
\"method_with_annotation\": %a \"allocation\": \
%a"
option_name (Pp.option F.pp_print_string) matcher.procedure
(Pp.option F.pp_print_string) matcher.procedure_regex
Expand All @@ -169,6 +184,7 @@ let matcher_of_config ~default_taint_target ~option_name matchers =
(Pp.option (Pp.seq ~sep:"," F.pp_print_string))
matcher.method_names (Pp.option F.pp_print_string)
matcher.overrides_of_class_with_annotation (Pp.option F.pp_print_string)
matcher.method_with_annotation (Pp.option F.pp_print_string)
matcher.allocation
in
{ procedure_matcher
Expand Down Expand Up @@ -241,6 +257,9 @@ let procedure_matches tenv matchers proc_name actuals =
String.equal (Procname.get_method superclass_pname) method_name )
tenv proc_name ) )
procedure_class_name )
| MethodWithAnnotation {annotation} ->
Annotations.pname_has_return_annot proc_name
(fun annot_item -> Annotations.ia_ends_with annot_item annotation)
| Allocation _ ->
false
in
Expand Down