[backend] Do not add return annotations to parameters of functions that are skipped

Reviewed By: sblackshear

Differential Revision: D5737278

fbshipit-source-id: 50ee2c8
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 9772b2299d
commit d5be23f1b6

@ -194,17 +194,30 @@ let rec nullify_exp_with_objc_null tenv prop exp =
| _ | _
-> prop -> prop
(** mark Exp.Var's or Exp.Lvar's as undefined *) (** mark Exp.Var's or Exp.Lvar's as undefined
let mark_vars_as_undefined tenv prop vars_to_mark callee_pname ret_annots loc path_pos = The annotations of the return type of the method get propagated to the return id,
let att_undef = PredSymb.Aundef (callee_pname, ret_annots, loc, path_pos) in with the exception of when the return type is a struct, and we translate it as passing a reference
let mark_var_as_undefined exp prop = to the method. *)
let mark_vars_as_undefined tenv prop ~ret_exp_opt ~undefined_actuals_by_ref callee_pname ret_annots
loc path_pos =
let mark_var_as_undefined ~annot exp prop =
match exp with match exp with
| Exp.Var _ | Lvar _ | Exp.Var _ | Lvar _
-> add_or_replace tenv prop (Apred (att_undef, [exp])) -> let att_undef = PredSymb.Aundef (callee_pname, annot, loc, path_pos) in
add_or_replace tenv prop (Apred (att_undef, [exp]))
| _ | _
-> prop -> prop
in in
List.fold ~f:(fun prop id -> mark_var_as_undefined id prop) ~init:prop vars_to_mark let prop_with_ret_attr =
match ret_exp_opt with
| Some ret_exp
-> mark_var_as_undefined ~annot:ret_annots ret_exp prop
| None
-> prop
in
List.fold
~f:(fun prop id -> mark_var_as_undefined ~annot:[] id prop)
~init:prop_with_ret_attr undefined_actuals_by_ref
(** type for arithmetic problems *) (** type for arithmetic problems *)
type arith_problem = type arith_problem =

@ -92,8 +92,8 @@ val nullify_exp_with_objc_null : Tenv.t -> Prop.normal Prop.t -> Exp.t -> Prop.n
remove the attribute and conjoin an equality to zero. *) remove the attribute and conjoin an equality to zero. *)
val mark_vars_as_undefined : val mark_vars_as_undefined :
Tenv.t -> Prop.normal Prop.t -> Exp.t list -> Typ.Procname.t -> Annot.Item.t -> Location.t Tenv.t -> Prop.normal Prop.t -> ret_exp_opt:Exp.t option -> undefined_actuals_by_ref:Exp.t list
-> PredSymb.path_pos -> Prop.normal Prop.t -> Typ.Procname.t -> Annot.Item.t -> Location.t -> PredSymb.path_pos -> Prop.normal Prop.t
(** mark Exp.Var's or Exp.Lvar's as undefined *) (** mark Exp.Var's or Exp.Lvar's as undefined *)
(** type for arithmetic problems *) (** type for arithmetic problems *)

@ -1578,16 +1578,12 @@ and unknown_or_scan_call ~is_scan ret_type_option ret_annots
[(Tabulation.remove_constant_string_class tenv pre_final, path)] [(Tabulation.remove_constant_string_class tenv pre_final, path)]
else else
(* otherwise, add undefined attribute to retvals and actuals passed by ref *) (* otherwise, add undefined attribute to retvals and actuals passed by ref *)
let exps_to_mark = let undefined_actuals_by_ref = List.map ~f:(fun (exp, _, _) -> exp) actuals_by_ref in
let ret_exps = Option.value_map ~f:(fun (id, _) -> [Exp.Var id]) ~default:[] ret_id in let ret_exp_opt = Option.map ~f:(fun (id, _) -> Exp.Var id) ret_id in
List.fold
~f:(fun exps_to_mark (exp, _, _) -> exp :: exps_to_mark)
~init:ret_exps actuals_by_ref
in
let prop_with_undef_attr = let prop_with_undef_attr =
let path_pos = State.get_path_pos () in let path_pos = State.get_path_pos () in
Attribute.mark_vars_as_undefined tenv pre_final exps_to_mark callee_pname ret_annots loc Attribute.mark_vars_as_undefined tenv pre_final ~ret_exp_opt ~undefined_actuals_by_ref
path_pos callee_pname ret_annots loc path_pos
in in
let reason = "function or method not found" in let reason = "function or method not found" in
let skip_path = Paths.Path.add_skipped_call path callee_pname reason in let skip_path = Paths.Path.add_skipped_call path callee_pname reason in

@ -97,6 +97,7 @@ SOURCES_ARC = \
npe/nil_in_dictionary_literal.m \ npe/nil_in_dictionary_literal.m \
npe/npe_conditional.m \ npe/npe_conditional.m \
npe/npe_self.m \ npe/npe_self.m \
npe/Npe_self_annotation.m \
npe/nullable.m \ npe/nullable.m \
property/ExplicitIvarName.m \ property/ExplicitIvarName.m \
shared/block/dispatch_examples.m \ shared/block/dispatch_examples.m \

@ -0,0 +1,29 @@
/*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <Foundation/Foundation.h>
@interface B : NSObject
@end
@interface A
+ (nullable NSData*)foo:(B*)b;
@end
@implementation B {
B* _decodedMetadata;
}
- (B*)decodedMetadata {
NSData* metadata = [A foo:self];
return _decodedMetadata; // No NPE here
}
@end
Loading…
Cancel
Save