forked from llvm-mirror/clang
-
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.
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
- Loading branch information
1 parent
b0eb287
commit e4c8953
Showing
5 changed files
with
197 additions
and
58 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,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 |
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,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) { } |