116d52a2aSJordan Rose #include <stdarg.h> 216d52a2aSJordan Rose 3f85a9b06SJordan Rose void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); 4f85a9b06SJordan Rose #if ARRAYS_CHECKED 5*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 6*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 7*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 8f85a9b06SJordan Rose #endif 9f85a9b06SJordan Rose 10f85a9b06SJordan Rose int *secondThingInTheFileThatNeedsNullabilityIsAPointer; 11f85a9b06SJordan Rose #if !ARRAYS_CHECKED 12f85a9b06SJordan Rose // expected-warning@-2 {{pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} 13*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the pointer may be null}} 14*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the pointer should never be null}} 15f85a9b06SJordan Rose #endif 16f85a9b06SJordan Rose 17f85a9b06SJordan Rose int *_Nonnull triggerConsistencyWarnings; 18f85a9b06SJordan Rose 19f85a9b06SJordan Rose void test( 20f85a9b06SJordan Rose int ints[], 21f85a9b06SJordan Rose #if ARRAYS_CHECKED 22*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 23*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 24*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 25f85a9b06SJordan Rose #endif 26f85a9b06SJordan Rose void *ptrs[], // expected-warning {{pointer is missing a nullability type specifier}} 27*06dd406eSJordan Rose // expected-note@-1 {{insert '_Nullable' if the pointer may be null}} 28*06dd406eSJordan Rose // expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}} 29f85a9b06SJordan Rose #if ARRAYS_CHECKED 30*06dd406eSJordan Rose // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 31*06dd406eSJordan Rose // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 32*06dd406eSJordan Rose // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 33f85a9b06SJordan Rose #endif 34f85a9b06SJordan Rose void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 35*06dd406eSJordan Rose // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 36*06dd406eSJordan Rose // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 37f85a9b06SJordan Rose #if ARRAYS_CHECKED 38*06dd406eSJordan Rose // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 39*06dd406eSJordan Rose // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 40*06dd406eSJordan Rose // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 41f85a9b06SJordan Rose #endif 42f85a9b06SJordan Rose 43f85a9b06SJordan Rose void testArraysOK( 44f85a9b06SJordan Rose int ints[_Nonnull], 45f85a9b06SJordan Rose void *ptrs[_Nonnull], // expected-warning {{pointer is missing a nullability type specifier}} 46*06dd406eSJordan Rose // expected-note@-1 {{insert '_Nullable' if the pointer may be null}} 47*06dd406eSJordan Rose // expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}} 48f85a9b06SJordan Rose void **nestedPtrs[_Nonnull]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 49*06dd406eSJordan Rose // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 50*06dd406eSJordan Rose // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 51f85a9b06SJordan Rose void testAllOK( 52f85a9b06SJordan Rose int ints[_Nonnull], 53f85a9b06SJordan Rose void * _Nullable ptrs[_Nonnull], 54f85a9b06SJordan Rose void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 55f85a9b06SJordan Rose 5616d52a2aSJordan Rose void testVAList(va_list ok); // no warning 5716d52a2aSJordan Rose 5816d52a2aSJordan Rose #if __cplusplus 5916d52a2aSJordan Rose // Carefully construct a test case such that if a platform's va_list is an array 6016d52a2aSJordan Rose // or pointer type, it gets tested, but otherwise it does not. 6116d52a2aSJordan Rose template<class T, class F> 6216d52a2aSJordan Rose struct pointer_like_or { typedef F type; }; 6316d52a2aSJordan Rose template<class T, class F> 6416d52a2aSJordan Rose struct pointer_like_or<T*, F> { typedef T *type; }; 6516d52a2aSJordan Rose template<class T, class F> 6616d52a2aSJordan Rose struct pointer_like_or<T* const, F> { typedef T * const type; }; 6716d52a2aSJordan Rose template<class T, class F> 6816d52a2aSJordan Rose struct pointer_like_or<T[], F> { typedef T type[]; }; 6916d52a2aSJordan Rose template<class T, class F, unsigned size> 7016d52a2aSJordan Rose struct pointer_like_or<T[size], F> { typedef T type[size]; }; 7116d52a2aSJordan Rose 7216d52a2aSJordan Rose void testVAListWithNullability( 7316d52a2aSJordan Rose pointer_like_or<va_list, void*>::type _Nonnull x); // no errors 7416d52a2aSJordan Rose #endif 7516d52a2aSJordan Rose 76f85a9b06SJordan Rose void nestedArrays(int x[5][1]) {} 77f85a9b06SJordan Rose #if ARRAYS_CHECKED 78*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 79*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 80*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 81f85a9b06SJordan Rose #endif 82f85a9b06SJordan Rose void nestedArraysOK(int x[_Nonnull 5][1]) {} 83f85a9b06SJordan Rose 84f85a9b06SJordan Rose #if !__cplusplus 85f85a9b06SJordan Rose void staticOK(int x[static 5][1]){} 86f85a9b06SJordan Rose #endif 87f85a9b06SJordan Rose 88f85a9b06SJordan Rose int globalArraysDoNotNeedNullability[5]; 89f85a9b06SJordan Rose 90f85a9b06SJordan Rose typedef int INTS[4]; 91f85a9b06SJordan Rose 92f85a9b06SJordan Rose void typedefTest( 93f85a9b06SJordan Rose INTS x, 94f85a9b06SJordan Rose #if ARRAYS_CHECKED 95*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 96*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 97*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 98f85a9b06SJordan Rose #endif 99f85a9b06SJordan Rose INTS _Nonnull x2, 100f85a9b06SJordan Rose _Nonnull INTS x3, 101f85a9b06SJordan Rose INTS y[2], 102f85a9b06SJordan Rose #if ARRAYS_CHECKED 103*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 104*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 105*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 106f85a9b06SJordan Rose #endif 107f85a9b06SJordan Rose INTS y2[_Nonnull 2]); 108f85a9b06SJordan Rose 109f85a9b06SJordan Rose 110f85a9b06SJordan Rose #pragma clang assume_nonnull begin 111f85a9b06SJordan Rose void testAssumeNonnull( 112f85a9b06SJordan Rose int ints[], 113f85a9b06SJordan Rose #if ARRAYS_CHECKED 114*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 115*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 116*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 117f85a9b06SJordan Rose #endif 118f85a9b06SJordan Rose void *ptrs[], 119f85a9b06SJordan Rose #if ARRAYS_CHECKED 120*06dd406eSJordan Rose // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 121*06dd406eSJordan Rose // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 122*06dd406eSJordan Rose // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 123f85a9b06SJordan Rose #endif 124f85a9b06SJordan Rose void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 125*06dd406eSJordan Rose // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 126*06dd406eSJordan Rose // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 127f85a9b06SJordan Rose #if ARRAYS_CHECKED 128*06dd406eSJordan Rose // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 129*06dd406eSJordan Rose // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 130*06dd406eSJordan Rose // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 131f85a9b06SJordan Rose #endif 132f85a9b06SJordan Rose 133f85a9b06SJordan Rose void testAssumeNonnullAllOK( 134f85a9b06SJordan Rose int ints[_Nonnull], 135f85a9b06SJordan Rose void * _Nullable ptrs[_Nonnull], 136f85a9b06SJordan Rose void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 137f85a9b06SJordan Rose void testAssumeNonnullAllOK2( 138f85a9b06SJordan Rose int ints[_Nonnull], 139f85a9b06SJordan Rose void * ptrs[_Nonnull], // backwards-compatibility 140f85a9b06SJordan Rose void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 141f85a9b06SJordan Rose #pragma clang assume_nonnull end 142