forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infer][clang] port the nullable suggestion on fields on C++
Summary: Suggesting to add `_Nullable` on the fields checked for, or assigned to, `nullptr` will allow the biabduction analysis to report null dereferences that are related to the lifetime of objects. Depends on D5832147 Reviewed By: sblackshear Differential Revision: D5836538 fbshipit-source-id: c1b8e48
- Loading branch information
1 parent
919b926
commit 4ec5440
Showing
6 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) 2016 - 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 | ||
# 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) | ||
|
||
include $(TESTS_DIR)/clang.make | ||
|
||
infer-out/report.json: $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
class T { | ||
private: | ||
int* _Nullable nullable_field; | ||
int* unnanotated_field; | ||
|
||
public: | ||
void assign_nullable_field_to_null_okay() { nullable_field = nullptr; } | ||
|
||
public: | ||
void assign_unnanotated_field_to_null_bad() { unnanotated_field = nullptr; } | ||
|
||
public: | ||
void test_nullable_field_for_null_okay() { | ||
if (nullable_field == nullptr) { | ||
} | ||
} | ||
|
||
public: | ||
void test_unnanotated_field_for_null_bad() { | ||
if (unnanotated_field == nullptr) { | ||
} | ||
} | ||
|
||
public: | ||
void FN_dereference_nullable_field_bad() { *nullable_field = 42; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
codetoanalyze/cpp/nullable/example.cpp, T_assign_nullable_field_to_null_okay, 0, FIELD_SHOULD_BE_NULLABLE, [Field nullable_field is assigned null here] | ||
codetoanalyze/cpp/nullable/example.cpp, T_assign_unnanotated_field_to_null_bad, 0, FIELD_SHOULD_BE_NULLABLE, [Field unnanotated_field is assigned null here] | ||
codetoanalyze/cpp/nullable/example.cpp, T_test_nullable_field_for_null_okay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nullable_field is compared to null here] | ||
codetoanalyze/cpp/nullable/example.cpp, T_test_unnanotated_field_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotated_field is compared to null here] |