blob: 869bbbd57e85e0cb0e58607b66f3b8a4dea965fd [file] [log] [blame]
Chris Lattner9b82ce92009-05-25 18:20:11 +00001// RUN: clang-cc -fblocks -fsyntax-only -verify %s
Ted Kremenek465172f2008-07-21 22:09:15 +00002
Ted Kremenekdbfe99e2009-07-15 23:23:54 +00003@class NSObject;
4
Ted Kremenek7fb43c12008-09-01 19:57:52 +00005int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
Ted Kremenek465172f2008-07-21 22:09:15 +00006int f2(int *x) __attribute__ ((nonnull (1)));
7int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}}
8int f4(int *x, int *y) __attribute__ ((nonnull (1,2)));
9int f5(int *x, int *y) __attribute__ ((nonnull (2,1)));
Ted Kremenekdbfe99e2009-07-15 23:23:54 +000010int f6(NSObject *x) __attribute__ ((nonnull (1))); // no-warning
11int f7(NSObject *x) __attribute__ ((nonnull)); // no-warning
12
Ted Kremenek465172f2008-07-21 22:09:15 +000013
Chris Lattner9b82ce92009-05-25 18:20:11 +000014extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull));
15
16extern void func3 (void (^block1)(), int, void (^block2)(), int)
17__attribute__((nonnull(1,3)));
18
19extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1)))
20__attribute__((nonnull(2)));
21
22void
23foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
24{
25 func1(cp1, cp2, i1);
26
27 func1(0, cp2, i1); // expected-warning {{null passed to a callee which requires a non-null argument}}
28 func1(cp1, 0, i1); // expected-warning {{null passed to a callee which requires a non-null argument}}
29 func1(cp1, cp2, 0);
30
31
32 func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee which requires a non-null argument}}
33 func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee which requires a non-null argument}}
34
35 func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}}
36 func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}}
Ted Kremenekdbfe99e2009-07-15 23:23:54 +000037
38 // Shouldn't these emit warnings? Clang doesn't, and neither does GCC. It
39 // seems that the checking should handle Objective-C pointers.
40 func6((NSObject*) 0); // no-warning
41 func7((NSObject*) 0); // no-warning
Chris Lattner9b82ce92009-05-25 18:20:11 +000042}