From ee7f07a1a930f33ecd37f00319e88b86f5703005 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Tue, 24 Jul 2018 04:52:26 -0700 Subject: [PATCH] Add missing case to block instruction converter Reviewed By: jvillard Differential Revision: D8951773 fbshipit-source-id: ce0d1f08c --- infer/src/IR/Procdesc.ml | 3 ++ .../objcpp/errors/BlockLfield.mm | 29 +++++++++++++++++++ .../codetoanalyze/objcpp/errors/issues.exp | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 infer/tests/codetoanalyze/objcpp/errors/BlockLfield.mm diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 9f3473425..a7350c326 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -728,6 +728,9 @@ let specialize_with_block_args_instrs resolved_pdesc substitutions = | Exp.Lvar origin_pvar -> let new_pvar = convert_pvar origin_pvar in Exp.Lvar new_pvar + | Exp.Lfield (Exp.Lvar origin_pvar, fname, typ) -> + let new_pvar = convert_pvar origin_pvar in + Exp.Lfield (Exp.Lvar new_pvar, fname, typ) | _ -> exp in diff --git a/infer/tests/codetoanalyze/objcpp/errors/BlockLfield.mm b/infer/tests/codetoanalyze/objcpp/errors/BlockLfield.mm new file mode 100644 index 000000000..08e789156 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/errors/BlockLfield.mm @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#import + +typedef struct { + const char* name; +} name_t; + +static void CFunWithBlockOk(void (^cb)(void)) { + name_t const* ns = NULL; + name_t n = ns[0]; // Lfield accessor (needs to be specialized correctly) + if (n.name != nil && cb != NULL) + cb(); +} + +@interface A : NSObject +- (void)mOk; +@end + +@implementation A +- (void)mOk { + CFunWithBlockOk(^(void){ + }); +} +@end diff --git a/infer/tests/codetoanalyze/objcpp/errors/issues.exp b/infer/tests/codetoanalyze/objcpp/errors/issues.exp index a20f8522f..89d9201c7 100644 --- a/infer/tests/codetoanalyze/objcpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/errors/issues.exp @@ -1,2 +1,4 @@ +codetoanalyze/objcpp/errors/BlockLfield.mm, A_mOk, 1, PRECONDITION_NOT_FOUND, no_bucket, ERROR, [start of procedure mOk] +codetoanalyze/objcpp/errors/BlockLfield.mm, CFunWithBlockOk, 2, PRECONDITION_NOT_MET, no_bucket, WARNING, [start of procedure CFunWithBlockOk()] codetoanalyze/objcpp/errors/c_functions.mm, main, 4, NULL_DEREFERENCE, B5, ERROR, [start of procedure main(),start of procedure autoUpdating,return from a call to A_autoUpdating,start of procedure autoUpdating2,Skipping dispatch_once2(): method has no implementation,return from a call to A_autoUpdating2,Executing synthesized getter block,start of procedure block,return from a call to objc_blockobjc_blockA_autoUpdating_1_2,Message block with receiver nil returns nil.] codetoanalyze/objcpp/errors/retain_cycles/RetainCycleWithStruct.mm, Animation_tracer, 2, RETAIN_CYCLE, no_bucket, ERROR, [start of procedure tracer,start of procedure _State,return from a call to _State__State,start of procedure initWithAnimation:,Taking true branch,return from a call to Tracer_initWithAnimation:]