From 453709c3c8c01c128ffc67cb2faac5f1c721e0dc Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 22 Jan 2016 07:53:39 -0800 Subject: [PATCH] Only propagate nullable to return value when environment variable is set. Reviewed By: jeremydubreil Differential Revision: D2852820 fb-gh-sync-id: f9d52ce --- infer/src/backend/ondemand.ml | 18 -------------- infer/src/backend/ondemand.mli | 3 --- infer/src/eradicate/eradicateChecks.ml | 34 ++++++++++++++++++++++---- infer/src/eradicate/models.ml | 2 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index f98973501..91d465c55 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -154,21 +154,3 @@ let do_analysis curr_pdesc proc_name = end | _ -> () (* skipping *) - - -(** Mark the return type @Nullable by modifying the spec. *) -let proc_add_return_nullable curr_pname = - match Specs.get_summary curr_pname with - | Some summary -> - let proc_attributes = Specs.get_attributes summary in - let method_annotation = proc_attributes.ProcAttributes.method_annotation in - let method_annotation' = Annotations.method_annotation_mark_return - Annotations.Nullable method_annotation in - let proc_attributes' = - { proc_attributes with - ProcAttributes.method_annotation = method_annotation' } in - let summary' = - { summary with - Specs.attributes = proc_attributes' } in - Specs.add_summary curr_pname summary' - | None -> () diff --git a/infer/src/backend/ondemand.mli b/infer/src/backend/ondemand.mli index 4bebe00ca..bda22215d 100644 --- a/infer/src/backend/ondemand.mli +++ b/infer/src/backend/ondemand.mli @@ -34,9 +34,6 @@ val one_cluster_per_procedure : unit -> bool (** Check if the procedure called by the current pdesc needs to be analyzed. *) val procedure_should_be_analyzed : Cfg.Procdesc.t -> Procname.t -> bool -(** Mark the return type @Nullable by modifying the spec. *) -val proc_add_return_nullable : Procname.t -> unit - (** Set the callbacks used to perform on-demand analysis. *) val set_callbacks : callbacks -> unit diff --git a/infer/src/eradicate/eradicateChecks.ml b/infer/src/eradicate/eradicateChecks.ml index 60f59dc8d..0b8456de4 100644 --- a/infer/src/eradicate/eradicateChecks.ml +++ b/infer/src/eradicate/eradicateChecks.ml @@ -27,6 +27,10 @@ let activate_field_over_annotated = Config.from_env_variable "ERADICATE_FIELD_OV (* activate the return over annotated warning *) let activate_return_over_annotated = Config.from_env_variable "ERADICATE_RETURN_OVER_ANNOTATED" +(* activate the propagation of nullable to the return value *) +let activate_propagate_return_nullable = + Config.from_env_variable "ERADICATE_PROPAGATE_RETURN_NULLABLE" + (* do not report RETURN_NOT_NULLABLE if the return is annotated @Nonnull *) let return_nonnull_silent = true @@ -42,7 +46,7 @@ let get_field_annotation fn typ = (* TODO (t4968422) eliminate not !Config.eradicate check by marking fields as nullified *) (* outside of Eradicate in some other way *) if (Models.Inference.enabled || not !Config.eradicate) - && Models.Inference.field_is_marked fn + && Models.Inference.field_is_marked fn then Annotations.mk_ia Annotations.Nullable ia else ia in Some (t, ia') @@ -325,6 +329,23 @@ let check_constructor_initialization | _ -> () end +(** Make the return type @Nullable by modifying the spec. *) +let spec_make_return_nullable curr_pname = + match Specs.get_summary curr_pname with + | Some summary -> + let proc_attributes = Specs.get_attributes summary in + let method_annotation = proc_attributes.ProcAttributes.method_annotation in + let method_annotation' = Annotations.method_annotation_mark_return + Annotations.Nullable method_annotation in + let proc_attributes' = + { proc_attributes with + ProcAttributes.method_annotation = method_annotation' } in + let summary' = + { summary with + Specs.attributes = proc_attributes' } in + Specs.add_summary curr_pname summary' + | None -> () + (** Check the annotations when returning from a method. *) let check_return_annotation find_canonical_duplicate curr_pname curr_pdesc exit_node ret_range @@ -352,10 +373,13 @@ let check_return_annotation activate_return_over_annotated in if return_not_nullable && Models.Inference.enabled then - Models.Inference.proc_add_return_nullable curr_pname; + Models.Inference.proc_mark_return_nullable curr_pname; - if return_not_nullable && !Config.ondemand_enabled then - Ondemand.proc_add_return_nullable curr_pname; + if return_not_nullable && + !Config.ondemand_enabled && + activate_propagate_return_nullable + then + spec_make_return_nullable curr_pname; if return_not_nullable || return_value_not_present then begin @@ -518,7 +542,7 @@ let check_overridden_annotations let _, overriden_ia, overriden_type = overriden_param in let () = if not (Annotations.ia_is_nullable current_ia) - && Annotations.ia_is_nullable overriden_ia then + && Annotations.ia_is_nullable overriden_ia then report_error find_canonical_duplicate start_node diff --git a/infer/src/eradicate/models.ml b/infer/src/eradicate/models.ml index 4d1049a52..dc4d5ade7 100644 --- a/infer/src/eradicate/models.ml +++ b/infer/src/eradicate/models.ml @@ -66,7 +66,7 @@ module Inference = struct mark_file_count dir fname (** Mark the return type @Nullable indirectly by writing to a global file. *) - let proc_add_return_nullable pn = + let proc_mark_return_nullable pn = let dir, fname = proc_get_ret_dir_fname pn in mark_file_count dir fname