diff options
author | Jordan Rose <jordan_rose@apple.com> | 2016-11-10 23:28:26 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2016-11-10 23:28:26 +0000 |
commit | e4c8953a90d27b73ed374cc11de694deb7801c20 (patch) | |
tree | 703b9cd117b68058efeb9e7f5d99183dcb9ee14c /test/SemaObjCXX | |
parent | b0eb2871c6471b7f99a3d8a25300fb57bb266804 (diff) |
Add -Wnullability-completeness-on-arrays.
This is an addition to (and sub-warning of) -Wnullability-completeness
that warns when an array parameter is missing nullability. When the
specific warning is switched off, the compiler falls back to only
warning on pointer types written as pointer types.
Note that use of nullability /within/ an array triggers the
completeness checks regardless of whether or not the array-specific
warning is enabled; the intent there is simply to determine whether a
particular header is trying to be nullability-aware at all.
Part of rdar://problem/25846421.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286520 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaObjCXX')
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-arrays.h | 87 | ||||
-rw-r--r-- | test/SemaObjCXX/nullability-consistency-arrays.mm | 12 |
2 files changed, 99 insertions, 0 deletions
diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h b/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h new file mode 100644 index 0000000000..dda35a6230 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h @@ -0,0 +1,87 @@ +void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +int *secondThingInTheFileThatNeedsNullabilityIsAPointer; +#if !ARRAYS_CHECKED +// expected-warning@-2 {{pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +int *_Nonnull triggerConsistencyWarnings; + +void test( + int ints[], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + void *ptrs[], // expected-warning {{pointer is missing a nullability type specifier}} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +void testArraysOK( + int ints[_Nonnull], + void *ptrs[_Nonnull], // expected-warning {{pointer is missing a nullability type specifier}} + void **nestedPtrs[_Nonnull]); // expected-warning 2 {{pointer is missing a nullability type specifier}} +void testAllOK( + int ints[_Nonnull], + void * _Nullable ptrs[_Nonnull], + void * _Nullable * _Nullable nestedPtrs[_Nonnull]); + +void nestedArrays(int x[5][1]) {} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +void nestedArraysOK(int x[_Nonnull 5][1]) {} + +#if !__cplusplus +void staticOK(int x[static 5][1]){} +#endif + +int globalArraysDoNotNeedNullability[5]; + +typedef int INTS[4]; + +void typedefTest( + INTS x, +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + INTS _Nonnull x2, + _Nonnull INTS x3, + INTS y[2], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + INTS y2[_Nonnull 2]); + + +#pragma clang assume_nonnull begin +void testAssumeNonnull( + int ints[], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + void *ptrs[], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +void testAssumeNonnullAllOK( + int ints[_Nonnull], + void * _Nullable ptrs[_Nonnull], + void * _Nullable * _Nullable nestedPtrs[_Nonnull]); +void testAssumeNonnullAllOK2( + int ints[_Nonnull], + void * ptrs[_Nonnull], // backwards-compatibility + void * _Nullable * _Nullable nestedPtrs[_Nonnull]); +#pragma clang assume_nonnull end diff --git a/test/SemaObjCXX/nullability-consistency-arrays.mm b/test/SemaObjCXX/nullability-consistency-arrays.mm new file mode 100644 index 0000000000..8ccd191e3b --- /dev/null +++ b/test/SemaObjCXX/nullability-consistency-arrays.mm @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -Wno-nullability-completeness -Werror +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -Wno-nullability-completeness -Werror + +#include "nullability-consistency-arrays.h" + +void h1(int *ptr) { } // don't warn + +void h2(int * _Nonnull p) { } |