1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 2236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 3236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian#define NULL (void*)0 4236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 5236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian#define ATTR __attribute__ ((__sentinel__)) 6236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 739834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedmanvoid foo1 (int x, ...) ATTR; // expected-note 3 {{function has been explicitly marked sentinel here}} 8236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanianvoid foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}} 9236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanianvoid foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}} 10236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanianvoid foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}} 11236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanianvoid foo10 (int x, ...) __attribute__ ((__sentinel__(1,1))); 12236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanianvoid foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}} 13236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 1439834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedman#define FOOMACRO(...) foo1(__VA_ARGS__) 1539834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedman 16b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattnervoid test1() { 17236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo1(1, NULL); // OK 18236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo1(1, 0) ; // expected-warning {{missing sentinel in function call}} 19236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo5(1, NULL, 2); // OK 20236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo5(1,2,NULL, 1); // OK 211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}} 22236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 23236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}} 24236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo6(1,NULL,3,4,5,6,7); // OK 25236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo7(1); // expected-warning {{not enough variable arguments in 'foo7' declaration to fit a sentinel}} 26236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo7(1, NULL); // OK 27236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 28236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}} 298eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall 308eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall // PR 5685 318eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall struct A {}; 328eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall struct A a, b, c; 338eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}} 348eb662ed5e04bd0f494c7dbefacb7d45660ab9faJohn McCall foo1(3, &a, &b, &c, (struct A*) 0); 3539834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedman 3639834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedman // PR11002 3739834ba5a9a9e998cc542f683d0e6327b406f088Eli Friedman FOOMACRO(1, 2); // expected-warning {{missing sentinel in function call}} 38236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian} 39236673e8fbd391cc7827efcaa64320344900d348Fariborz Jahanian 40b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 41b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 42b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattnervoid (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1))); 43b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 44b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattnervoid test2() { 45b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}} 46b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}} 47b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 48b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 49b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}} 50b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 51b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner b(1, "%s", (void*)0); // OK 52b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner b(1, "%s", 0); // expected-warning {{missing sentinel in function call}} 53b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}} 54b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner z(1, "%s", (void*)0, 1, 0); // OK 55b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 56b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}} 57b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner 58b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner y(1, "%s", (void*)0,3,4,5,6,7); // OK 59b1332d7a5228600ae86276b12883ec0ac9500ec1Chris Lattner} 60