[infer][clang] translate the annotations on fields

Summary: Translate the annotations on C++ fields.

Reviewed By: sblackshear

Differential Revision: D5847193

fbshipit-source-id: 591600f
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent f3b158a158
commit b63f5d7c00

@ -122,8 +122,7 @@ let rec get_struct_fields tenv decl =
| FieldDecl (_, {ni_name}, qt, _)
-> let id = CGeneral_utils.mk_class_field_name class_tname ni_name in
let typ = qual_type_to_sil_type tenv qt in
let annotation_items = [] in
(* For the moment we don't use them*)
let annotation_items = CAst_utils.sil_annot_of_type qt in
[(id, typ, annotation_items)]
| _
-> []

@ -8,8 +8,9 @@
*/
class T {
private:
int* _Nullable nullable_field;
int* unnanotated_field;
int* _Nullable nullable_field;
int* _Nonnull nonnull_field;
public:
void assign_nullable_field_to_null_okay() { nullable_field = nullptr; }
@ -17,6 +18,9 @@ class T {
public:
void assign_unnanotated_field_to_null_bad() { unnanotated_field = nullptr; }
public:
void assign_nonnull_field_to_null_bad() { nonnull_field = nullptr; }
public:
void test_nullable_field_for_null_okay() {
if (nullable_field == nullptr) {
@ -30,5 +34,31 @@ class T {
}
public:
void FN_dereference_nullable_field_bad() { *nullable_field = 42; }
void test_nonnull_field_for_null_bad() {
if (nonnull_field == nullptr) {
}
}
public:
void dereference_unnanotated_field_okay() { *unnanotated_field = 42; }
public:
void dereference_nonnull_field_okay() { *nonnull_field = 42; }
public:
void dereference_nullable_field_bad() { *nullable_field = 42; }
public:
void dereference_unnanotated_field_after_test_for_null_bad() {
if (unnanotated_field == nullptr) {
*unnanotated_field = 42;
}
}
public:
void FP_dereference_nonnull_field_after_test_for_null_okay() {
if (nonnull_field == nullptr) {
*nonnull_field = 42;
}
}
};

@ -1,4 +1,9 @@
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_FP_dereference_nonnull_field_after_test_for_null_okay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnull_field is compared to null here]
codetoanalyze/cpp/nullable/example.cpp, T_FP_dereference_nonnull_field_after_test_for_null_okay, 2, NULL_DEREFERENCE, [start of procedure FP_dereference_nonnull_field_after_test_for_null_okay,Condition is true]
codetoanalyze/cpp/nullable/example.cpp, T_assign_nonnull_field_to_null_bad, 0, FIELD_SHOULD_BE_NULLABLE, [Field nonnull_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_dereference_nullable_field_bad, 0, NULL_DEREFERENCE, [start of procedure dereference_nullable_field_bad]
codetoanalyze/cpp/nullable/example.cpp, T_dereference_unnanotated_field_after_test_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotated_field is compared to null here]
codetoanalyze/cpp/nullable/example.cpp, T_dereference_unnanotated_field_after_test_for_null_bad, 2, NULL_DEREFERENCE, [start of procedure dereference_unnanotated_field_after_test_for_null_bad,Condition is true]
codetoanalyze/cpp/nullable/example.cpp, T_test_nonnull_field_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnull_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]

Loading…
Cancel
Save