Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s |
Ted Kremenek | 465172f | 2008-07-21 22:09:15 +0000 | [diff] [blame] | 2 | |
Ted Kremenek | dbfe99e | 2009-07-15 23:23:54 +0000 | [diff] [blame] | 3 | @class NSObject; |
| 4 | |
Ted Kremenek | 7fb43c1 | 2008-09-01 19:57:52 +0000 | [diff] [blame] | 5 | int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}} |
Ted Kremenek | 465172f | 2008-07-21 22:09:15 +0000 | [diff] [blame] | 6 | int f2(int *x) __attribute__ ((nonnull (1))); |
| 7 | int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}} |
| 8 | int f4(int *x, int *y) __attribute__ ((nonnull (1,2))); |
| 9 | int f5(int *x, int *y) __attribute__ ((nonnull (2,1))); |
Ted Kremenek | dbfe99e | 2009-07-15 23:23:54 +0000 | [diff] [blame] | 10 | int f6(NSObject *x) __attribute__ ((nonnull (1))); // no-warning |
| 11 | int f7(NSObject *x) __attribute__ ((nonnull)); // no-warning |
| 12 | |
Ted Kremenek | 465172f | 2008-07-21 22:09:15 +0000 | [diff] [blame] | 13 | |
Chris Lattner | 9b82ce9 | 2009-05-25 18:20:11 +0000 | [diff] [blame] | 14 | extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull)); |
| 15 | |
| 16 | extern void func3 (void (^block1)(), int, void (^block2)(), int) |
| 17 | __attribute__((nonnull(1,3))); |
| 18 | |
| 19 | extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1))) |
| 20 | __attribute__((nonnull(2))); |
| 21 | |
Chris Lattner | e030358 | 2010-01-09 20:43:19 +0000 | [diff] [blame^] | 22 | void func6(); |
| 23 | void func7(); |
| 24 | |
Chris Lattner | 9b82ce9 | 2009-05-25 18:20:11 +0000 | [diff] [blame] | 25 | void |
| 26 | foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)()) |
| 27 | { |
| 28 | func1(cp1, cp2, i1); |
| 29 | |
| 30 | func1(0, cp2, i1); // expected-warning {{null passed to a callee which requires a non-null argument}} |
| 31 | func1(cp1, 0, i1); // expected-warning {{null passed to a callee which requires a non-null argument}} |
| 32 | func1(cp1, cp2, 0); |
| 33 | |
| 34 | |
| 35 | func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee which requires a non-null argument}} |
| 36 | func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee which requires a non-null argument}} |
| 37 | |
| 38 | func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}} |
| 39 | func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}} |
Ted Kremenek | dbfe99e | 2009-07-15 23:23:54 +0000 | [diff] [blame] | 40 | |
| 41 | // Shouldn't these emit warnings? Clang doesn't, and neither does GCC. It |
| 42 | // seems that the checking should handle Objective-C pointers. |
| 43 | func6((NSObject*) 0); // no-warning |
| 44 | func7((NSObject*) 0); // no-warning |
Chris Lattner | 9b82ce9 | 2009-05-25 18:20:11 +0000 | [diff] [blame] | 45 | } |