3 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wno-objc-root-class %s
8 int f1(int x); // no warning
9 int f2(int *x) __attribute__ ((nonnull (1)));
10 int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}}
11 int f4(int *x, int *y) __attribute__ ((nonnull (1,2)));
12 int f5(int *x, int *y) __attribute__ ((nonnull (2,1)));
13 int f6(NSObject *x) __attribute__ ((nonnull (1))); // no-warning
14 int f7(NSObject *x) __attribute__ ((nonnull)); // no-warning
17 extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull));
19 extern void func3 (void (^block1)(), int, void (^block2)(), int)
20 __attribute__((nonnull(1,3)));
22 extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1)))
23 __attribute__((nonnull(2)));
25 void func6(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}}
29 foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
33 func1(0, cp2, i1); // expected-warning {{null passed to a callee that requires a non-null argument}}
34 func1(cp1, 0, i1); // expected-warning {{null passed to a callee that requires a non-null argument}}
38 func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee that requires a non-null argument}}
39 func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee that requires a non-null argument}}
41 func4(0, cp1); // expected-warning {{null passed to a callee that requires a non-null argument}}
42 func4(cp1, 0); // expected-warning {{null passed to a callee that requires a non-null argument}}
44 func6((NSObject*) 0); // expected-warning {{passing arguments to 'func6' without a prototype is deprecated in all versions of C and is not supported in C2x}}
45 func7((NSObject*) 0); // expected-warning {{passing arguments to 'func7' without a prototype is deprecated in all versions of C and is not supported in C2x}}
48 void func5(int) NONNULL_ATTR; // no warning
51 struct dispatch_object_s {
57 struct dispatch_object_s *_do;
58 } dispatch_object_t __attribute__((transparent_union));
60 __attribute__((nonnull))
61 void _dispatch_queue_push_list(dispatch_object_t _head); // no warning
63 void func6(dispatch_object_t _head) { // expected-note {{conflicting prototype is here}}
64 _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
65 _dispatch_queue_push_list(_head._do); // no warning
72 - (void)doSomethingWithNonNullPointer:(void *)ptr :(int)iarg : (void*)ptr1 __attribute__((nonnull(1, 3)));
73 + (void)doSomethingClassyWithNonNullPointer:(void *)ptr __attribute__((nonnull(1)));
74 - (void*)returnsCNonNull __attribute__((returns_nonnull)); // no-warning
75 - (id)returnsObjCNonNull __attribute__((returns_nonnull)); // no-warning
76 - (int)returnsIntNonNull __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}}
79 extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
85 - (void*) testRetNull __attribute__((returns_nonnull));
91 [object doSomethingWithNonNullPointer:NULL:1:NULL]; // expected-warning 2 {{null passed to a callee that requires a non-null argument}}
92 [object doSomethingWithNonNullPointer:vp:1:NULL]; // expected-warning {{null passed to a callee that requires a non-null argument}}
93 [NSObject doSomethingClassyWithNonNullPointer:NULL]; // expected-warning {{null passed to a callee that requires a non-null argument}}
94 DoSomethingNotNull(NULL); // expected-warning {{null passed to a callee that requires a non-null argument}}
95 [object doSomethingWithNonNullPointer:vp:1:vp];
97 - (void*) testRetNull {
98 return 0; // expected-warning {{null returned from method that requires a non-null return value}}
102 __attribute__((objc_root_class))
103 @interface TestNonNullParameters
104 - (void) doNotPassNullParameterNonPointerArg:(int)__attribute__((nonnull))x; // expected-warning {{'nonnull' attribute only applies to pointer arguments}}
105 - (void) doNotPassNullParameter:(id)__attribute__((nonnull))x;
106 - (void) doNotPassNullParameterArgIndex:(id)__attribute__((nonnull(1)))x; // expected-warning {{'nonnull' attribute when used on parameters takes no arguments}}
107 - (void) doNotPassNullOnMethod:(id)x __attribute__((nonnull(1)));
110 void test(TestNonNullParameters *f) {
111 [f doNotPassNullParameter:0]; // expected-warning {{null passed to a callee that requires a non-null argument}}
112 [f doNotPassNullParameterArgIndex:0]; // no-warning
113 [f doNotPassNullOnMethod:0]; // expected-warning {{null passed to a callee that requires a non-null argument}}
117 void PR18795(int (^g)(const char *h, ...) __attribute__((nonnull(1))) __attribute__((nonnull))) {
118 g(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
120 void PR18795_helper() {
121 PR18795(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
124 void (^PR23117)(int *) = ^(int *p1) __attribute__((nonnull(1))) {};
127 #pragma clang assume_nonnull begin
130 #pragma clang assume_nonnull end