diff --git a/Makefile b/Makefile index 11ea82a92..749db0eef 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ ifneq ($(PYTHON_lxml),no) BUILD_SYSTEMS_TESTS += results_xml endif ifneq ($(XCODE_SELECT),no) -BUILD_SYSTEMS_TESTS += xcodebuild_no_xcpretty objc_getters_setters +BUILD_SYSTEMS_TESTS += xcodebuild_no_xcpretty objc_getters_setters objc_missing_fld DIRECT_TESTS += \ objc_frontend objc_errors objc_linters objc_ioslints \ objcpp_frontend objcpp_linters objc_linters-for-test-only objcpp_linters-for-test-only \ diff --git a/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.h b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.h new file mode 100644 index 000000000..c8e360cb5 --- /dev/null +++ b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.h @@ -0,0 +1,11 @@ +/* + * 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 + +@interface A : NSObject +@property(assign) id delegate; +@end diff --git a/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.m b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.m new file mode 100644 index 000000000..9ce5051fd --- /dev/null +++ b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/A.m @@ -0,0 +1,28 @@ +/* + * 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 "A.h" + +@implementation A +- (void)implOnlyFn:(int)v { +} +@end + +bool predA() { + A* a = [A new]; + [a implOnlyFn:1]; + return (a.delegate ? 0 : 0); +} + +// NULL_DEREFERECE is (correctly) reported on only one of the branches +int badOnlyOneNDA() { + int x, *p1 = 0, *p2 = 0; + if (predA()) + x = *p1; + else + x = *p2; + return x; +} diff --git a/infer/tests/build_systems/codetoanalyze/objc_missing_fld/B.m b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/B.m new file mode 100644 index 000000000..b53f66244 --- /dev/null +++ b/infer/tests/build_systems/codetoanalyze/objc_missing_fld/B.m @@ -0,0 +1,26 @@ +/* + * 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 +#import "A.h" + +bool predB() { + A* a = [A new]; + // implOnlyFn added in A.m (is valid but missing from the tenv for B.m) + [a implOnlyFn:1]; + // Missing_fld reported here causing the spec to be missing + return (a.delegate ? 0 : 0); +} + +// NULL_DEREFERENCE is reported on both branches since fB() lacks a spec +int badOnlyOneNDB() { + int x, *p1 = 0, *p2 = 0; + if (predB()) + x = *p1; + else + x = *p2; + return x; +} diff --git a/infer/tests/build_systems/objc_missing_fld/Makefile b/infer/tests/build_systems/objc_missing_fld/Makefile new file mode 100644 index 000000000..b192a3ba7 --- /dev/null +++ b/infer/tests/build_systems/objc_missing_fld/Makefile @@ -0,0 +1,21 @@ +# Copyright (c) 2017-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. + +TESTS_DIR = ../.. +ROOT_DIR = $(TESTS_DIR)/../.. +CODETOANALYZE_DIR = ../codetoanalyze/objc_missing_fld + +ANALYZER = checkers +SOURCES = $(CODETOANALYZE_DIR)/A.m $(CODETOANALYZE_DIR)/B.m +OBJECTS = $(CODETOANALYZE_DIR)/A.o $(CODETOANALYZE_DIR)/B.o +INFER_OPTIONS = --biabduction-only --report-custom-error --developer-mode --project-root $(TESTS_DIR) +INFERPRINT_OPTIONS = --project-root $(TESTS_DIR) --issues-tests + +include $(TESTS_DIR)/infer.make + +infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(MAKEFILE_LIST) + $(QUIET)$(REMOVE_DIR) buck-out && \ + $(call silent_on_success,Testing analysis with Objective-C getters and setters,\ + $(INFER_BIN) $(INFER_OPTIONS) --results-dir $(CURDIR)/infer-out -- clang -c $(SOURCES)) diff --git a/infer/tests/build_systems/objc_missing_fld/issues.exp b/infer/tests/build_systems/objc_missing_fld/issues.exp new file mode 100644 index 000000000..2660760f4 --- /dev/null +++ b/infer/tests/build_systems/objc_missing_fld/issues.exp @@ -0,0 +1,3 @@ +build_systems/codetoanalyze/objc_missing_fld/A.m, badOnlyOneNDA, 5, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure badOnlyOneNDA(),start of procedure predA(),start of procedure implOnlyFn:,return from a call to A_implOnlyFn:,Executing synthesized getter delegate,Condition is true,return from a call to predA,Taking false branch] +build_systems/codetoanalyze/objc_missing_fld/B.m, badOnlyOneNDB, 3, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure badOnlyOneNDB(),Taking true branch] +build_systems/codetoanalyze/objc_missing_fld/B.m, badOnlyOneNDB, 5, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure badOnlyOneNDB(),Taking false branch]