diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 14:00:56 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 14:00:56 +0000 |
commit | 2e645aa5697838f16ec570eb07c2bee7e13d0e0b (patch) | |
tree | a764184c2fc9486979b074250b013a0937ee64e5 /test/SemaObjCXX | |
parent | 798321d8eb5630cd4a8f490a4f25e32ef195fb07 (diff) | |
download | src-2e645aa5697838f16ec570eb07c2bee7e13d0e0b.tar.gz src-2e645aa5697838f16ec570eb07c2bee7e13d0e0b.zip |
Notes
Diffstat (limited to 'test/SemaObjCXX')
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-1.h | 17 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-2.h | 16 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-3.h | 1 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-4.h | 1 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-5.h | 14 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-6.h | 8 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-7.h | 40 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-8.h | 27 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h | 8 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-pragmas-1.h | 101 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-pragmas-2.h | 12 | ||||
-rw-r--r-- | test/SemaObjCXX/Inputs/nullability-pragmas-3.h | 0 | ||||
-rw-r--r-- | test/SemaObjCXX/nullability-consistency.mm | 16 | ||||
-rw-r--r-- | test/SemaObjCXX/nullability-pragmas.mm | 41 |
14 files changed, 302 insertions, 0 deletions
diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-1.h b/test/SemaObjCXX/Inputs/nullability-consistency-1.h new file mode 100644 index 000000000000..4d6bf79f9a46 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-1.h @@ -0,0 +1,17 @@ +void f1(int *ptr); // expected-warning{{pointer is missing a nullability type specifier}} + +void f2(int * __nonnull); + +#include "nullability-consistency-2.h" + +void f3(int *ptr) { // expected-warning{{pointer is missing a nullability type specifier}} + int *other = ptr; // shouldn't warn +} + +class X { + void mf(int *ptr); // expected-warning{{pointer is missing a nullability type specifier}} + int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}} +}; + + + diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-2.h b/test/SemaObjCXX/Inputs/nullability-consistency-2.h new file mode 100644 index 000000000000..8efdfa8394e1 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-2.h @@ -0,0 +1,16 @@ +void g1(int * __nonnull); + +void g2(int (^block)(int, int)); // expected-warning{{block pointer is missing a nullability type specifier}} + +void g3(const + id // expected-warning{{missing a nullability type specifier}} + volatile + * // expected-warning{{missing a nullability type specifier}} + ); + +@interface SomeClass +@property (retain,nonnull) id property1; +@property (retain,nullable) SomeClass *property2; +- (nullable SomeClass *)method1; +- (void)method2:(nonnull SomeClass *)param; +@end diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-3.h b/test/SemaObjCXX/Inputs/nullability-consistency-3.h new file mode 100644 index 000000000000..a0c0d381bb8e --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-3.h @@ -0,0 +1 @@ +void double_declarator1(int *__nonnull *); // expected-warning{{pointer is missing a nullability type specifier (__nonnull, __nullable, or __null_unspecified)}} diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-4.h b/test/SemaObjCXX/Inputs/nullability-consistency-4.h new file mode 100644 index 000000000000..984280c17ebe --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-4.h @@ -0,0 +1 @@ +void double_declarator1(int * * __nonnull); // expected-warning{{pointer is missing a nullability type specifier (__nonnull, __nullable, or __null_unspecified)}} diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-5.h b/test/SemaObjCXX/Inputs/nullability-consistency-5.h new file mode 100644 index 000000000000..3a685af614ef --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-5.h @@ -0,0 +1,14 @@ +#define SUPPRESS_NULLABILITY_WARNING(Type) \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") \ + Type \ + _Pragma("clang diagnostic pop") + +void suppress1(SUPPRESS_NULLABILITY_WARNING(int *) ptr); // no warning + +void shouldwarn5(int *ptr); //expected-warning{{missing a nullability type specifier}} + +void trigger5(int * __nonnull); + +void suppress2(SUPPRESS_NULLABILITY_WARNING(int *) ptr); // no warning + diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-6.h b/test/SemaObjCXX/Inputs/nullability-consistency-6.h new file mode 100644 index 000000000000..cb712e94c661 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-6.h @@ -0,0 +1,8 @@ +int *ptr; // expected-warning {{missing a nullability type specifier}} + +#pragma clang assume_nonnull begin + +extern void **blah; // expected-warning 2{{missing a nullability type specifier}} + +#pragma clang assume_nonnull end + diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-7.h b/test/SemaObjCXX/Inputs/nullability-consistency-7.h new file mode 100644 index 000000000000..ddbdfada7991 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-7.h @@ -0,0 +1,40 @@ +#ifndef SOMEKIT_H +#define SOMEKIT_H + +__attribute__((objc_root_class)) +#ifndef NS_ASSUME_NONNULL_BEGIN +#if __has_feature(assume_nonnull) +#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define NS_ASSUME_NONNULL_BEGIN +#define NS_ASSUME_NONNULL_END +#endif +#endif + +NS_ASSUME_NONNULL_BEGIN + +@interface A +-(null_unspecified A*)transform:(null_unspecified A*)input __attribute__((unavailable("anything but this"))); +-(A*)transform:(A*)input integer:(int)integer; + +@property (null_unspecified, nonatomic, readonly, retain) A* someA; +@property (null_unspecified, nonatomic, retain) A* someOtherA; + +@property (nonatomic) int intValue __attribute__((unavailable("wouldn't work anyway"))); +@end + +NS_ASSUME_NONNULL_END + + +__attribute__((unavailable("just don't"))) +@interface B : A +@end + +@interface C : A +- (instancetype)init; // expected-warning{{pointer is missing a nullability type specifier}} +- (instancetype)initWithA:( A*)a __attribute__((objc_designated_initializer)); // expected-warning 2{{pointer is missing a nullability type specifier}} +@end + +#endif + diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-8.h b/test/SemaObjCXX/Inputs/nullability-consistency-8.h new file mode 100644 index 000000000000..890bb4db5465 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-8.h @@ -0,0 +1,27 @@ +typedef int* __nonnull mynonnull; + +__attribute__((objc_root_class)) +@interface typedefClass +- (void) func1:(mynonnull)i; +@end + +void func2(mynonnull i); + +void func3(int *); // expected-warning{{pointer is missing a nullability type specifier}} + +#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) +typedef void *CFTypeRef; +void cf1(CFTypeRef * p CF_RETURNS_NOT_RETAINED); // expected-warning {{pointer is missing a nullability type specifier}} + +void cf2(CFTypeRef * __nullable p CF_RETURNS_NOT_RETAINED); +void cf3(CFTypeRef * __nonnull p CF_RETURNS_NOT_RETAINED); + +void cf4(CFTypeRef __nullable * __nullable p CF_RETURNS_NOT_RETAINED); +void cf5(CFTypeRef __nonnull * __nullable p CF_RETURNS_NOT_RETAINED); + +void cf6(CFTypeRef * __nullable CF_RETURNS_NOT_RETAINED p); +void cf7(CF_RETURNS_NOT_RETAINED CFTypeRef * __nonnull p); + +typedef CFTypeRef __nullable *CFTypeRefPtr; +void cfp1(CFTypeRefPtr p CF_RETURNS_NOT_RETAINED); // expected-warning {{pointer is missing a nullability type specifier}} +void cfp2(CFTypeRefPtr __nonnull p CF_RETURNS_NOT_RETAINED); diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h b/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h new file mode 100644 index 000000000000..6dbca1663d5a --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h @@ -0,0 +1,8 @@ +// Simply marking this as "#pragma clang system_header" didn't tickle the bug, rdar://problem/21134250. + +void system1(int *ptr); +#if WARN_IN_SYSTEM_HEADERS +// expected-warning@-2{{pointer is missing a nullability type specifier}} +#endif + +void system2(int * __nonnull); diff --git a/test/SemaObjCXX/Inputs/nullability-pragmas-1.h b/test/SemaObjCXX/Inputs/nullability-pragmas-1.h new file mode 100644 index 000000000000..950111692419 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-pragmas-1.h @@ -0,0 +1,101 @@ +__attribute__((objc_root_class)) +@interface NSError +@end + +__attribute__((objc_root_class)) +@interface A +@end + +struct X { }; + +void f1(int *x); // expected-warning{{pointer is missing a nullability type specifier}} + +typedef struct __attribute__((objc_bridge(NSError))) __CFError *CFErrorRef; +typedef NSError *NSErrorPtr; +typedef NSError **NSErrorPtrPtr; +typedef CFErrorRef *CFErrorRefPtr; +typedef int *int_ptr; +typedef A *A_ptr; +typedef int (^block_ptr)(int, int); + +#pragma clang assume_nonnull begin + +void f2(int *x); +void f3(A* obj); +void f4(int (^block)(int, int)); +void f5(int_ptr x); +void f6(A_ptr obj); +void f7(int * __nullable x); +void f8(A * __nullable obj); +void f9(int X::* mem_ptr); +void f10(int (X::*mem_func)(int, int)); +void f11(int X::* __nullable mem_ptr); +void f12(int (X::* __nullable mem_func)(int, int)); + +int_ptr f13(void); +A *f14(void); + +int * __null_unspecified f15(void); +A * __null_unspecified f16(void); +void f17(CFErrorRef *error); // expected-note{{no known conversion from 'A * __nonnull' to 'CFErrorRef __nullable * __nullable' (aka '__CFError **') for 1st argument}} +void f18(A **); // expected-warning 2{{pointer is missing a nullability type specifier}} +void f19(CFErrorRefPtr error); // expected-warning{{pointer is missing a nullability type specifier}} + +void g1(int (^)(int, int)); +void g2(int (^ *bp)(int, int)); // expected-warning{{block pointer is missing a nullability type specifier}} +// expected-warning@-1{{pointer is missing a nullability type specifier}} +void g3(block_ptr *bp); // expected-warning{{block pointer is missing a nullability type specifier}} +// expected-warning@-1{{pointer is missing a nullability type specifier}} +void g4(int (*fp)(int, int)); +void g5(int (**fp)(int, int)); // expected-warning 2{{pointer is missing a nullability type specifier}} + +@interface A(Pragmas1) ++ (instancetype)aWithA:(A *)a; +- (A *)method1:(A_ptr)ptr; +- (null_unspecified A *)method2; +- (void)method3:(NSError **)error; // expected-note{{passing argument to parameter 'error' here}} +- (void)method4:(NSErrorPtr *)error; // expected-note{{passing argument to parameter 'error' here}} +- (void)method5:(NSErrorPtrPtr)error; +// expected-warning@-1{{pointer is missing a nullability type specifier}} + +@property A *aProp; +@property NSError **anError; // expected-warning 2{{pointer is missing a nullability type specifier}} +@end + +int *global_int_ptr; + +// typedefs not inferred __nonnull +typedef int *int_ptr_2; + +typedef int * // expected-warning{{pointer is missing a nullability type specifier}} + *int_ptr_ptr; + +static inline void f30(void) { + float *fp = global_int_ptr; // expected-error{{cannot initialize a variable of type 'float *' with an lvalue of type 'int * __nonnull'}} + + int_ptr_2 ip2; + float *fp2 = ip2; // expected-error{{cannot initialize a variable of type 'float *' with an lvalue of type 'int_ptr_2' (aka 'int *')}} + + int_ptr_ptr ipp; + float *fp3 = ipp; // expected-error{{lvalue of type 'int_ptr_ptr' (aka 'int **')}} +} + +@interface AA : A { +@public + id ivar1; + __nonnull id ivar2; +} +@end + +#pragma clang assume_nonnull end + +void f20(A *a); // expected-warning{{pointer is missing a nullability type specifier}} +void f21(int_ptr x); // expected-warning{{pointer is missing a nullability type specifier}} +void f22(A_ptr y); // expected-warning{{pointer is missing a nullability type specifier}} +void f23(int_ptr __nullable x); +void f24(A_ptr __nullable y); +void f25(int_ptr_2 x); // expected-warning{{pointer is missing a nullability type specifier}} + +@interface A(OutsidePragmas1) ++ (instancetype)aWithInt:(int)value; // expected-warning{{pointer is missing a nullability type specifier}} +@end diff --git a/test/SemaObjCXX/Inputs/nullability-pragmas-2.h b/test/SemaObjCXX/Inputs/nullability-pragmas-2.h new file mode 100644 index 000000000000..da3d21de6962 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-pragmas-2.h @@ -0,0 +1,12 @@ +#pragma clang assume_nonnull start // expected-error{{expected 'begin' or 'end'}} + +#pragma clang assume_nonnull begin // expected-note{{#pragma entered here}} + +#include "nullability-pragmas-3.h" // expected-error{{cannot #include files inside '#pragma clang assume_nonnull'}} + +#pragma clang assume_nonnull begin // expected-note{{#pragma entered here}} +#pragma clang assume_nonnull begin // expected-error{{already inside '#pragma clang assume_nonnull'}} +#pragma clang assume_nonnull end + +#pragma clang assume_nonnull begin // expected-error{{'#pragma clang assume_nonnull' was not ended within this file}} + diff --git a/test/SemaObjCXX/Inputs/nullability-pragmas-3.h b/test/SemaObjCXX/Inputs/nullability-pragmas-3.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/test/SemaObjCXX/Inputs/nullability-pragmas-3.h diff --git a/test/SemaObjCXX/nullability-consistency.mm b/test/SemaObjCXX/nullability-consistency.mm new file mode 100644 index 000000000000..acb972da0b85 --- /dev/null +++ b/test/SemaObjCXX/nullability-consistency.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -isystem %S/Inputs/nullability-consistency-system %s -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -isystem %S/Inputs/nullability-consistency-system %s -Wsystem-headers -DWARN_IN_SYSTEM_HEADERS -verify + +#include "nullability-consistency-1.h" +#include "nullability-consistency-3.h" +#include "nullability-consistency-4.h" +#include "nullability-consistency-5.h" +#include "nullability-consistency-5.h" +#include "nullability-consistency-6.h" +#include "nullability-consistency-7.h" +#include "nullability-consistency-8.h" +#include "nullability-consistency-system.h" + +void h1(int *ptr) { } // don't warn + +void h2(int * __nonnull) { } diff --git a/test/SemaObjCXX/nullability-pragmas.mm b/test/SemaObjCXX/nullability-pragmas.mm new file mode 100644 index 000000000000..0c61a30b333f --- /dev/null +++ b/test/SemaObjCXX/nullability-pragmas.mm @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -verify + +#include "nullability-pragmas-1.h" +#include "nullability-pragmas-2.h" + +#if !__has_feature(assume_nonnull) +# error assume_nonnull feature is not set +#endif + +void test_pragmas_1(A * __nonnull a, AA * __nonnull aa) { + f1(0); // okay: no nullability annotations + f2(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f3(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f4(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f5(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f6(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f7(0); // okay + f8(0); // okay + f9(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f10(0); // expected-warning{{null passed to a callee that requires a non-null argument}} + f11(0); // okay + f12(0); // okay + [a method1:0]; // expected-warning{{null passed to a callee that requires a non-null argument}} + + f17(a); // expected-error{{no matching function for call to 'f17'}} + [a method3: a]; // expected-error{{cannot initialize a parameter of type 'NSError * __nullable * __nullable' with an lvalue of type 'A * __nonnull'}} + [a method4: a]; // expected-error{{cannot initialize a parameter of type 'NSErrorPtr __nullable * __nullable' (aka 'NSError **') with an lvalue of type 'A * __nonnull'}} + + float *ptr; + ptr = f13(); // expected-error{{assigning to 'float *' from incompatible type 'int_ptr __nonnull' (aka 'int *')}} + ptr = f14(); // expected-error{{assigning to 'float *' from incompatible type 'A * __nonnull'}} + ptr = [a method1:a]; // expected-error{{assigning to 'float *' from incompatible type 'A * __nonnull'}} + ptr = a.aProp; // expected-error{{assigning to 'float *' from incompatible type 'A * __nonnull'}} + ptr = global_int_ptr; // expected-error{{assigning to 'float *' from incompatible type 'int * __nonnull'}} + ptr = f15(); // expected-error{{assigning to 'float *' from incompatible type 'int * __null_unspecified'}} + ptr = f16(); // expected-error{{assigning to 'float *' from incompatible type 'A * __null_unspecified'}} + ptr = [a method2]; // expected-error{{assigning to 'float *' from incompatible type 'A * __null_unspecified'}} + + ptr = aa->ivar1; // expected-error{{from incompatible type 'id'}} + ptr = aa->ivar2; // expected-error{{from incompatible type 'id __nonnull'}} +} |