3 // RUN: %clang_cc1 -fblocks -fsyntax-only -verify %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)));
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 which requires a non-null argument}}
34 func1(cp1, 0, i1); // expected-warning {{null passed to a callee which requires a non-null argument}}
38 func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee which requires a non-null argument}}
39 func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee which requires a non-null argument}}
41 func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}}
42 func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}}
44 // Shouldn't these emit warnings? Clang doesn't, and neither does GCC. It
45 // seems that the checking should handle Objective-C pointers.
46 func6((NSObject*) 0); // no-warning
47 func7((NSObject*) 0); // no-warning
50 void func5(int) NONNULL_ATTR; // no warning
53 struct dispatch_object_s {
59 struct dispatch_object_s *_do;
60 } dispatch_object_t __attribute__((transparent_union));
62 __attribute__((nonnull))
63 void _dispatch_queue_push_list(dispatch_object_t _head); // no warning
65 void func6(dispatch_object_t _head) {
66 _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee which requires a non-null argument}}
67 _dispatch_queue_push_list(_head._do); // no warning