[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / attr-sentinel.c
blob9af11296b07f60a4d4fafea29b226554d34f4219
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 #define NULL (void*)0
5 #define ATTR __attribute__ ((__sentinel__))
7 void foo1 (int x, ...) ATTR; // expected-note 3 {{function has been explicitly marked sentinel here}}
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}}
14 #define FOOMACRO(...) foo1(__VA_ARGS__)
16 void test1(void) {
17 foo1(1, NULL); // OK
18 foo1(1, 0) ; // expected-warning {{missing sentinel in function call}}
19 foo5(1, NULL, 2); // OK
20 foo5(1,2,NULL, 1); // OK
21 foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}}
23 foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
24 foo6(1,NULL,3,4,5,6,7); // OK
25 foo7(1); // expected-warning {{not enough variable arguments in 'foo7' declaration to fit a sentinel}}
26 foo7(1, NULL); // OK
28 foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}}
30 // PR 5685
31 struct A {};
32 struct A a, b, c;
33 foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}}
34 foo1(3, &a, &b, &c, (struct A*) 0);
36 // PR11002
37 FOOMACRO(1, 2); // expected-warning {{missing sentinel in function call}}
42 void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
44 void test2(void) {
45 void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
46 void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
49 void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
51 b(1, "%s", (void*)0); // OK
52 b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
53 z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
54 z(1, "%s", (void*)0, 1, 0); // OK
56 y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
58 y(1, "%s", (void*)0,3,4,5,6,7); // OK