From 15a0662149c498be0361ea2421c8d0d7ce2137f3 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 3 Mar 2017 07:58:29 -0800 Subject: [PATCH] [clang] Adding annotations for ObjC instance variables Reviewed By: sblackshear Differential Revision: D4649995 fbshipit-source-id: 668c2b8 --- infer/src/IR/Typ.re | 3 ++- infer/src/clang/cField_decl.ml | 9 ++++--- .../tests/codetoanalyze/objc/errors/Makefile | 1 + .../codetoanalyze/objc/errors/issues.exp | 1 + .../annotations/nullable_annotations_fields.m | 27 +++++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 infer/tests/codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m diff --git a/infer/src/IR/Typ.re b/infer/src/IR/Typ.re index 7863e9331..e4283b6e6 100644 --- a/infer/src/IR/Typ.re +++ b/infer/src/IR/Typ.re @@ -321,7 +321,8 @@ let module Struct = { name ( Pp.seq ( - fun f (fld, t, _) => F.fprintf f "\n\t\t%a %a" (pp_full pe) t Ident.pp_fieldname fld + fun f (fld, t, a) => + F.fprintf f "\n\t\t%a %a %a" (pp_full pe) t Ident.pp_fieldname fld Annot.Item.pp a ) ) fields diff --git a/infer/src/clang/cField_decl.ml b/infer/src/clang/cField_decl.ml index 72493ab3c..d56303c2e 100644 --- a/infer/src/clang/cField_decl.ml +++ b/infer/src/clang/cField_decl.ml @@ -45,11 +45,12 @@ let build_sil_field type_ptr_to_sil_type tenv field_name type_ptr prop_attribute let typ = type_ptr_to_sil_type tenv type_ptr in let item_annotations = match prop_atts with | [] -> - [({ Annot.class_name = Config.ivar_attributes; parameters = annotation_from_type typ }, - true)] + ({ Annot.class_name = Config.ivar_attributes; parameters = annotation_from_type typ }, + true) | _ -> - [({ Annot.class_name = Config.property_attributes; parameters = prop_atts }, - true)] in + ({ Annot.class_name = Config.property_attributes; parameters = prop_atts }, + true) in + let item_annotations = item_annotations :: (CAst_utils.sil_annot_of_type type_ptr) in fname, typ, item_annotations (* Given a list of declarations in an interface returns a list of fields *) diff --git a/infer/tests/codetoanalyze/objc/errors/Makefile b/infer/tests/codetoanalyze/objc/errors/Makefile index e48b364ce..23be442a2 100644 --- a/infer/tests/codetoanalyze/objc/errors/Makefile +++ b/infer/tests/codetoanalyze/objc/errors/Makefile @@ -51,6 +51,7 @@ SOURCES_DEFAULT = \ shared/protocol_procdesc/Bicycle.m \ shared/protocol_procdesc/main.c \ shared/annotations/nullable_annotations.m \ + shared/annotations/nullable_annotations_fields.m \ taint/sources.m \ taint/viewController.m \ diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index 26e644d63..978824de2 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -115,6 +115,7 @@ codetoanalyze/objc/errors/taint/sources.m, testNSHTTPCookie4, 5, TAINTED_VALUE_R codetoanalyze/objc/errors/taint/viewController.m, ExampleDelegate_application:openURL:sourceApplication:annotation:, 7, TAINTED_VALUE_REACHING_SENSITIVE_FUNCTION, [start of procedure application:openURL:sourceApplication:annotation:,start of procedure init,return from a call to VCA_init,start of procedure ExampleSanitizer(),Condition is false,return from a call to ExampleSanitizer,Condition is false,Condition is true] codetoanalyze/objc/shared/annotations/nullable_annotations.m, User_otherUserName, 2, NULL_DEREFERENCE, [start of procedure otherUserName] codetoanalyze/objc/shared/annotations/nullable_annotations.m, npe_property_nullable, 3, NULL_DEREFERENCE, [start of procedure npe_property_nullable()] +codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m, A_nullable_field, 3, NULL_DEREFERENCE, [start of procedure nullable_field] codetoanalyze/objc/shared/block/block-it.m, MyBlock_array, 3, RETURN_VALUE_IGNORED, [start of procedure array,Condition is true] codetoanalyze/objc/shared/block/block-it.m, __objc_anonymous_block_MyBlock_array______1, 5, UNINITIALIZED_VALUE, [start of procedure block,Condition is false] codetoanalyze/objc/shared/block/block-it.m, __objc_anonymous_block_MyBlock_array_trans______2, 4, UNINITIALIZED_VALUE, [start of procedure block,Condition is false] diff --git a/infer/tests/codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m b/infer/tests/codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m new file mode 100644 index 000000000..3b447eb49 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/shared/annotations/nullable_annotations_fields.m @@ -0,0 +1,27 @@ +/* + * 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 + +@interface A : NSObject + +@end + +A* getA(); + +@implementation A { + int x; + A* _Nullable _child; +} +- (int)nullable_field { + A* a = getA(); + A* child = a->_child; + return child->x; +} + +@end