1//RUN: %clang_cc1 -fsyntax-only -verify %s 2 3#include <stdarg.h> 4 5void a(const char *a, ...) __attribute__((format(printf, 1,2))); // no-error 6void b(const char *a, ...) __attribute__((format(printf, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}} 7void c(const char *a, ...) __attribute__((format(printf, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}} 8void d(const char *a, int c) __attribute__((format(printf, 1,2))); // expected-error {{format attribute requires variadic function}} 9void e(char *str, int c, ...) __attribute__((format(printf, 2,3))); // expected-error {{format argument not a string type}} 10 11typedef const char* xpto; 12void f(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error 13void g(xpto c) __attribute__((format(printf, 1, 0))); // no-error 14 15void y(char *str) __attribute__((format(strftime, 1,0))); // no-error 16void z(char *str, int c, ...) __attribute__((format(strftime, 1,2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}} 17 18int (*f_ptr)(char*,...) __attribute__((format(printf, 1,2))); // no-error 19int (*f2_ptr)(double,...) __attribute__((format(printf, 1, 2))); // expected-error {{format argument not a string type}} 20 21struct _mystruct { 22 int (*printf)(const char *format, ...) __attribute__((__format__(printf, 1, 2))); // no-error 23 int (*printf2)(double format, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format argument not a string type}} 24}; 25 26typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error 27 28// <rdar://problem/6623513> 29int rdar6623513(void *, const char*, const char*, ...) 30 __attribute__ ((format (printf, 3, 0))); 31 32int rdar6623513_aux(int len, const char* s) { 33 rdar6623513(0, "hello", "%.*s", len, s); 34} 35 36 37 38// same as format(printf(...))... 39void a2(const char *a, ...) __attribute__((format(printf0, 1,2))); // no-error 40void b2(const char *a, ...) __attribute__((format(printf0, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}} 41void c2(const char *a, ...) __attribute__((format(printf0, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}} 42void d2(const char *a, int c) __attribute__((format(printf0, 1,2))); // expected-error {{format attribute requires variadic function}} 43void e2(char *str, int c, ...) __attribute__((format(printf0, 2,3))); // expected-error {{format argument not a string type}} 44 45// FreeBSD usage 46#define __printf0like(fmt,va) __attribute__((__format__(__printf0__,fmt,va))) 47void null(int i, const char *a, ...) __printf0like(2,0); // no-error 48void null(int i, const char *a, ...) { // expected-note{{passing argument to parameter 'a' here}} 49 if (a) 50 (void)0/* vprintf(...) would go here */; 51} 52 53void callnull(void){ 54 null(0, 0); // no error 55 null(0, (char*)0); // no error 56 null(0, (void*)0); // no error 57 null(0, (int*)0); // expected-warning {{incompatible pointer types}} 58} 59 60// FreeBSD kernel extensions 61void a3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1,2))); // no-error 62void b3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}} 63void c3(const char *a, ...) __attribute__((format(freebsd_kprintf, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}} 64void d3(const char *a, int c) __attribute__((format(freebsd_kprintf, 1,2))); // expected-error {{format attribute requires variadic function}} 65void e3(char *str, int c, ...) __attribute__((format(freebsd_kprintf, 2,3))); // expected-error {{format argument not a string type}} 66 67 68 69// PR4470 70int xx_vprintf(const char *, va_list); 71 72const char *foo(const char *format) __attribute__((format_arg(1))); 73 74void __attribute__((format(printf, 1, 0))) 75foo2(const char *fmt, va_list va) { 76 xx_vprintf(foo(fmt), va); 77} 78 79// PR6542 80extern void gcc_format (const char *, ...) 81 __attribute__ ((__format__(__gcc_diag__, 1, 2))); 82extern void gcc_cformat (const char *, ...) 83 __attribute__ ((__format__(__gcc_cdiag__, 1, 2))); 84extern void gcc_cxxformat (const char *, ...) 85 __attribute__ ((__format__(__gcc_cxxdiag__, 1, 2))); 86extern void gcc_tformat (const char *, ...) 87 __attribute__ ((__format__(__gcc_tdiag__, 1, 2))); 88 89const char *foo3(const char *format) __attribute__((format_arg("foo"))); // expected-error{{'format_arg' attribute requires parameter 1 to be an integer constant}} 90