From 8bdbf3aedc977364f27bc151d75946b776f34c8a Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Wed, 27 Jun 2018 06:38:43 -0700 Subject: [PATCH] Fix false positive BAD_POINTER for objcpp Reviewed By: dulmarod Differential Revision: D8658824 fbshipit-source-id: e582ce8 --- infer/lib/linter_rules/linters.al | 2 +- infer/tests/codetoanalyze/objc/linters/badpointer.m | 7 ------- infer/tests/codetoanalyze/objc/linters/issues.exp | 11 +++++------ .../codetoanalyze/objcpp/linters/BadPointer.mm | 13 +++++++++++++ infer/tests/codetoanalyze/objcpp/linters/Makefile | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 infer/tests/codetoanalyze/objcpp/linters/BadPointer.mm diff --git a/infer/lib/linter_rules/linters.al b/infer/lib/linter_rules/linters.al index 24a9f3751..3944372c5 100644 --- a/infer/lib/linter_rules/linters.al +++ b/infer/lib/linter_rules/linters.al @@ -48,7 +48,7 @@ DEFINE-CHECKER BAD_POINTER_COMPARISON = { OR is_binop_with_kind("LT") OR is_binop_with_kind("LE")) AND ( (is_node("ImplicitCastExpr") AND has_type("NSNumber *") - AND (has_cast_kind("IntegralToPointer") OR has_cast_kind("NullToPointer")) + AND has_cast_kind("IntegralToPointer") ) HOLDS-NEXT); LET root_is_stmt_expecting_bool = diff --git a/infer/tests/codetoanalyze/objc/linters/badpointer.m b/infer/tests/codetoanalyze/objc/linters/badpointer.m index 0f2b5dc12..a30d362c9 100644 --- a/infer/tests/codetoanalyze/objc/linters/badpointer.m +++ b/infer/tests/codetoanalyze/objc/linters/badpointer.m @@ -115,13 +115,6 @@ int good5(NSNumber* number, Simple* simple) { return 1; } -int bad7(NSNumber* number) { - if (number < 0) { - return 0; - } - return 1; -} - int bad8(NSNumber* number) { if (number) { return 0; diff --git a/infer/tests/codetoanalyze/objc/linters/issues.exp b/infer/tests/codetoanalyze/objc/linters/issues.exp index d35957180..0bc5ddb29 100644 --- a/infer/tests/codetoanalyze/objc/linters/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters/issues.exp @@ -20,17 +20,16 @@ codetoanalyze/objc/linters/atomic_prop.m, A_readQ, 84, POINTER_TO_INTEGRAL_IMPLI codetoanalyze/objc/linters/atomic_prop.m, A_writeQ, 80, DIRECT_ATOMIC_PROPERTY_ACCESS, no_bucket, WARNING, [] codetoanalyze/objc/linters/atomic_prop.m, objc_block_1, 112, DIRECT_ATOMIC_PROPERTY_ACCESS, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad1, 15, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad10, 137, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad11, 146, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad12, 159, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] +codetoanalyze/objc/linters/badpointer.m, bad10, 130, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] +codetoanalyze/objc/linters/badpointer.m, bad11, 139, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] +codetoanalyze/objc/linters/badpointer.m, bad12, 152, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad2, 24, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad3, 31, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad4, 83, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad5, 97, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/badpointer.m, bad6, 104, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad7, 119, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad8, 126, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] -codetoanalyze/objc/linters/badpointer.m, bad9, 133, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] +codetoanalyze/objc/linters/badpointer.m, bad8, 119, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] +codetoanalyze/objc/linters/badpointer.m, bad9, 126, BAD_POINTER_COMPARISON, no_bucket, WARNING, [] codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_call_with_boxed_int, 67, POINTER_TO_INTEGRAL_IMPLICIT_CAST, no_bucket, WARNING, [] codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_call_with_string, 60, POINTER_TO_INTEGRAL_IMPLICIT_CAST, no_bucket, WARNING, [] codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_ivar_dictionary_item_call_funct_with_int, 45, POINTER_TO_INTEGRAL_IMPLICIT_CAST, no_bucket, WARNING, [] diff --git a/infer/tests/codetoanalyze/objcpp/linters/BadPointer.mm b/infer/tests/codetoanalyze/objcpp/linters/BadPointer.mm new file mode 100644 index 000000000..f87662e36 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/linters/BadPointer.mm @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015-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 + +void good_nil_check(NSNumber* duration) { + if (duration != nil) { + } +} diff --git a/infer/tests/codetoanalyze/objcpp/linters/Makefile b/infer/tests/codetoanalyze/objcpp/linters/Makefile index 53b31a5d8..0c2fe5df9 100644 --- a/infer/tests/codetoanalyze/objcpp/linters/Makefile +++ b/infer/tests/codetoanalyze/objcpp/linters/Makefile @@ -9,9 +9,10 @@ ANALYZER = linters CLANG_OPTIONS = -x objective-c++ -std=c++11 -fobjc-arc -c INFER_OPTIONS = --no-filtering --debug-exceptions --project-root $(TESTS_DIR) \ --enable-issue-type GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL -INFERPRINT_OPTIONS = --issues-tests +INFERPRINT_OPTIONS = --issues-tests SOURCES = \ + $(wildcard *.mm) \ $(wildcard */*.mm) \ include $(TESTS_DIR)/clang.make