Beispiel #1
0
void test2() {
    void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__));  // expected-note {{function has been explicitly marked sentinel here}}
    void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}


    void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}

    b(1, "%s", (void*)0); // OK
    b(1, "%s", 0);  // expected-warning {{missing sentinel in function call}}
    z(1, "%s",4 ,1,0);  // expected-warning {{missing sentinel in function call}}
    z(1, "%s", (void*)0, 1, 0); // OK

    y(1, "%s", 1,2,3,4,5,6,7);  // expected-warning {{missing sentinel in function call}}

    y(1, "%s", (void*)0,3,4,5,6,7); // OK
}
// RUN: %clang_cc1  -fsyntax-only -verify %s

#define NULL (void*)0

#define ATTR __attribute__ ((__sentinel__)) 

void foo1 (int x, ...) ATTR; // expected-note {{function has been explicitly marked sentinel here}}
void foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}}
void foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}}
void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}}
void foo10 (int x, ...) __attribute__ ((__sentinel__(1,1)));
void foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}}

int main ()
{

  foo1(1, NULL); // OK
  foo1(1, 0) ; // expected-warning {{missing sentinel in function call}}
  foo5(1, NULL, 2);  // OK
  foo5(1,2,NULL, 1); // OK
  foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}}

  foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
  foo6(1,NULL,3,4,5,6,7); // OK
  foo7(1); // expected-warning {{not enough variable arguments in 'foo7' declaration to fit a sentinel}}
  foo7(1, NULL); // OK

  foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}}
}
 
// RUN: clang-cc -fsyntax-only -verify %s

void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));

int main()
{
        void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__));  // expected-note {{function has been explicitly marked sentinel here}}
        void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}


        void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}

	b(1, "%s", (void*)0);	// OK
	b(1, "%s", 0);  // expected-warning {{missing sentinel in function call}}
	z(1, "%s",4 ,1,0);  // expected-warning {{missing sentinel in function call}}
	z(1, "%s", (void*)0, 1, 0);	// OK

	y(1, "%s", 1,2,3,4,5,6,7);  // expected-warning {{missing sentinel in function call}}

	y(1, "%s", (void*)0,3,4,5,6,7);	// OK

}

// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s

void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));

int main() {
    void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{'sentinel' attribute only supported for variadic blocks}}
    bbad = ^void (int arg, const char * format) __attribute__ ((__sentinel__)) {} ; // expected-warning {{'sentinel' attribute only supported for variadic blocks}}
    void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) =  // expected-note {{block has been explicitly marked sentinel here}}
    ^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
    void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}


    void (^y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))) = ^ __attribute__ ((__sentinel__ (5))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}

    b(1, "%s", (void*)0); // OK
    b(1, "%s", 0);  // expected-warning {{missing sentinel in block call}}
    z(1, "%s",4 ,1,0);  // expected-warning {{missing sentinel in block call}}
    z(1, "%s", (void*)0, 1, 0); // OK

    y(1, "%s", 1,2,3,4,5,6,7);  // expected-warning {{missing sentinel in block call}}

    y(1, "%s", (void*)0,3,4,5,6,7); // OK

}

/* APPLE LOCAL file radar 6246527 */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
#include <stddef.h>

void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
void (^e1) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1, 3))); /* { dg-error "wrong number of arguments" "sentinel" } */

int main()
{
        void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) = 
						^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
        void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {};


        void (^y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))) = ^ __attribute__ ((__sentinel__ (5))) (int arg, const char * format, ...) {};

	b(1, "%s", NULL);	// OK
	b(1, "%s", 0); /* { dg-warning "missing sentinel in function call" } */                                                         	
	z(1, "%s",4 ,1,0); /* { dg-warning "missing sentinel in function call" } */
	z(1, "%s", NULL, 1, 0);	// OK

	y(1, "%s", 1,2,3,4,5,6,7); /* { dg-warning "missing sentinel in function call" } */

	y(1, "%s", NULL,3,4,5,6,7);	// OK

}

Beispiel #6
0
#include <stddef.h> /* For NULL, which must be (ptr)0.  */

extern int execl (const char *, const char *, ...);
extern int execlp (const char *, const char *, ...);
extern int execle (const char *, const char *, ...);
extern char *envp[];

#define ATTR __attribute__ ((__sentinel__))

extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */

extern void foo1 (const char *, ...) ATTR;
extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */
extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */
extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */
extern void foo5 (const char *, ...) __attribute__ ((__sentinel__(1)));
extern void foo6 (const char *, ...) __attribute__ ((__sentinel__(5)));
extern void foo7 (const char *, ...) __attribute__ ((__sentinel__(0)));
extern void foo8 (const char *, ...) __attribute__ ((__sentinel__("a"))); /* { dg-warning "not an integer constant" "sentinel" } */
extern void foo9 (const char *, ...) __attribute__ ((__sentinel__(-1))); /* { dg-warning "less than zero" "sentinel" } */
/* APPLE LOCAL begin two arg sentinel 5631180 */
extern void foo10 (const char *, ...) __attribute__ ((__sentinel__(1,1)));
extern void foo11 (const char *, ...) __attribute__ ((__sentinel__(1,1,3))); /* { dg-error "wrong number of arguments" "sentinel" } */
/* APPLE LOCAL end two arg sentinel 5631180 */

extern void bar(void)
{
  foo1 (); /* { dg-error "not enough|too few arguments" "sentinel" } */
  foo1 (NULL); /* { dg-warning "not enough" "sentinel" } */
  foo1 ("a"); /* { dg-warning "not enough" "sentinel" } */
  foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */