[infer][objc] example of nullable annotation suggestion on Objective C

Summary: Example of combination between annotating fields with nullable and the biabduction analysis in Objective C

Reviewed By: dulmarod

Differential Revision: D5906016

fbshipit-source-id: b95c6e0
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 9f9dbdb914
commit 14d01620d2

@ -65,7 +65,7 @@ BUILD_SYSTEMS_TESTS += xcodebuild_no_xcpretty
DIRECT_TESTS += \
objc_frontend objc_errors objc_linters objc_ioslints \
objcpp_frontend objcpp_linters objc_linters-for-test-only objcpp_linters-for-test-only \
objc_linters-def-folder
objc_linters-def-folder objc_checkers
ifneq ($(XCPRETTY),no)
BUILD_SYSTEMS_TESTS += xcodebuild
endif
@ -406,7 +406,7 @@ ifeq ($(BUILD_C_ANALYZERS),yes)
test -d $(DESTDIR)$(libdir)/infer/infer/lib/linter_rules/ || \
$(MKDIR_P) $(DESTDIR)$(libdir)/infer/infer/lib/linter_rules
test -d $(DESTDIR)$(libdir)/infer/infer/etc/ || \
$(MKDIR_P) $(DESTDIR)$(libdir)/infer/infer/etc
$(MKDIR_P) $(DESTDIR)$(libdir)/infer/infer/etc
endif
ifeq ($(BUILD_JAVA_ANALYZERS),yes)
test -d $(DESTDIR)$(libdir)/infer/infer/lib/java/ || \

@ -11,7 +11,6 @@ ANALYZER = checkers
# see explanations in cpp/errors/Makefile for the custom isystem
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c
INFER_OPTIONS = --biabduction --suggest-nullable --debug-exceptions --project-root $(TESTS_DIR)
INFER_OPTIONS += --debug
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.cpp)

@ -0,0 +1,19 @@
# 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.
TESTS_DIR = ../../..
ANALYZER = checkers
CLANG_OPTIONS = -c
INFER_OPTIONS = --biabduction --suggest-nullable --debug-exceptions --project-root $(TESTS_DIR)
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.m)
include $(TESTS_DIR)/clang.make
infer-out/report.json: $(MAKEFILE_LIST)

@ -0,0 +1,72 @@
/*
* 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/NSString.h>
@interface T : NSObject
- (void)assignUnnanotatedFieldToNullBad;
@end
@implementation T {
int* unnanotatedField;
int* __nullable nullableField;
int* nonnullField;
}
- (void)assignNullableFieldToNullOkay {
nullableField = nil;
}
- (void)assignUnnanotatedFieldToNullBad {
unnanotatedField = nil;
}
- (void)assignNonnullFieldToNullBad {
nonnullField = nil;
}
- (void)testNullableFieldForNullOkay {
if (nullableField == nil) {
}
}
- (void)testUnnanotatedFieldForNullBad {
if (unnanotatedField == nil) {
}
}
- (void)testNonnullFieldForNullBad {
if (nonnullField == nil) {
}
}
- (void)dereferenceUnnanotatedFieldOkay {
*unnanotatedField = 42;
}
- (void)dereferenceNonnullFieldOkay {
*nonnullField = 42;
}
- (void)dereferenceNullableFieldBad {
*nullableField = 42;
}
- (void)dereferenceUnnanotatedFieldAfterTestForNullBad {
if (unnanotatedField == nil) {
*unnanotatedField = 42;
}
}
- (void)FP_dereferenceNonnullFieldAfterTestForNullOkay {
if (nonnullField == nil) {
*nonnullField = 42;
}
}
@end

@ -0,0 +1,9 @@
codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here]
codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 2, NULL_DEREFERENCE, [start of procedure FP_dereferenceNonnullFieldAfterTestForNullOkay,Condition is true]
codetoanalyze/objc/checkers/Nullable.m, T_assignNonnullFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is assigned null here]
codetoanalyze/objc/checkers/Nullable.m, T_assignUnnanotatedFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is assigned null here]
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFieldBad, 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableFieldBad]
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is compared to null here]
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 2, NULL_DEREFERENCE, [start of procedure dereferenceUnnanotatedFieldAfterTestForNullBad,Condition is true]
codetoanalyze/objc/checkers/Nullable.m, T_testNonnullFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here]
codetoanalyze/objc/checkers/Nullable.m, T_testUnnanotatedFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is compared to null here]
Loading…
Cancel
Save