Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Fariborz Jahanian | 236673e | 2009-05-14 18:00:00 +0000 | [diff] [blame] | 2 | |
| 3 | #define NULL (void*)0 |
| 4 | |
| 5 | #define ATTR __attribute__ ((__sentinel__)) |
| 6 | |
John McCall | 8eb662e | 2010-05-06 23:53:00 +0000 | [diff] [blame] | 7 | void foo1 (int x, ...) ATTR; // expected-note 2 {{function has been explicitly marked sentinel here}} |
Fariborz Jahanian | 236673e | 2009-05-14 18:00:00 +0000 | [diff] [blame] | 8 | void foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}} |
| 9 | void foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}} |
| 10 | void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}} |
| 11 | void foo10 (int x, ...) __attribute__ ((__sentinel__(1,1))); |
| 12 | void foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}} |
| 13 | |
Chris Lattner | b1332d7 | 2010-03-22 21:02:14 +0000 | [diff] [blame] | 14 | void test1() { |
Fariborz Jahanian | 236673e | 2009-05-14 18:00:00 +0000 | [diff] [blame] | 15 | foo1(1, NULL); // OK |
| 16 | foo1(1, 0) ; // expected-warning {{missing sentinel in function call}} |
| 17 | foo5(1, NULL, 2); // OK |
| 18 | foo5(1,2,NULL, 1); // OK |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 19 | foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}} |
Fariborz Jahanian | 236673e | 2009-05-14 18:00:00 +0000 | [diff] [blame] | 20 | |
| 21 | foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}} |
| 22 | foo6(1,NULL,3,4,5,6,7); // OK |
| 23 | foo7(1); // expected-warning {{not enough variable arguments in 'foo7' declaration to fit a sentinel}} |
| 24 | foo7(1, NULL); // OK |
| 25 | |
| 26 | foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}} |
John McCall | 8eb662e | 2010-05-06 23:53:00 +0000 | [diff] [blame] | 27 | |
| 28 | // PR 5685 |
| 29 | struct A {}; |
| 30 | struct A a, b, c; |
| 31 | foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}} |
| 32 | foo1(3, &a, &b, &c, (struct A*) 0); |
Fariborz Jahanian | 236673e | 2009-05-14 18:00:00 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Chris Lattner | b1332d7 | 2010-03-22 21:02:14 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1))); |
| 38 | |
| 39 | void test2() { |
| 40 | void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}} |
| 41 | void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}} |
| 42 | |
| 43 | |
| 44 | void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}} |
| 45 | |
| 46 | b(1, "%s", (void*)0); // OK |
| 47 | b(1, "%s", 0); // expected-warning {{missing sentinel in function call}} |
| 48 | z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}} |
| 49 | z(1, "%s", (void*)0, 1, 0); // OK |
| 50 | |
| 51 | y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}} |
| 52 | |
| 53 | y(1, "%s", (void*)0,3,4,5,6,7); // OK |
| 54 | } |