brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.8 KiB · 820abd8 Raw
117 lines · c
1//RUN: %clang_cc1 -fsyntax-only -verify %s2 3#include <stdarg.h>4 5void a(const char *a, ...) __attribute__((format(printf, 1, 2)));    // no-error6void 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-warning {{GCC requires a function with the 'format' attribute to be variadic}}9void e(char *str, int c, ...) __attribute__((format(printf, 2, 3))); // expected-error {{format argument not a string type}}10void f(int a, const char *b, ...) __attribute__((format(printf, 2, 1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}11void g(int a, const char *b, ...) __attribute__((format(printf, 2, 2))); // expected-error {{'format' attribute parameter 3 is out of bounds}}12void h(int a, const char *b, ...) __attribute__((format(printf, 2, 3))); // no-error13void i(const char *a, int b, ...) __attribute__((format(printf, 1, 2))); // expected-error {{'format' attribute parameter 3 is out of bounds}}14 15typedef const char *xpto;16void j(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error17void k(xpto c) __attribute__((format(printf, 1, 0)));               // no-error18 19void y(char *str) __attribute__((format(strftime, 1, 0)));             // no-error20void z(char *str, int c, ...) __attribute__((format(strftime, 1, 2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}}21 22int (*f_ptr)(char*,...) __attribute__((format(printf, 1,2))); // no-error23int (*f2_ptr)(double,...) __attribute__((format(printf, 1, 2))); // expected-error {{format argument not a string type}}24 25struct _mystruct {26  int (*printf)(const char *format, ...) __attribute__((__format__(printf, 1, 2))); // no-error27  int (*printf2)(double format, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format argument not a string type}}28};29 30typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error31 32int rdar6623513(void *, const char*, const char*, ...)33  __attribute__ ((format (printf, 3, 0)));34 35int rdar6623513_aux(int len, const char* s) {36  rdar6623513(0, "hello", "%.*s", len, s);37}38 39// same as format(printf(...))...40void a2(const char *a, ...) __attribute__((format(printf0, 1, 2)));    // no-error41void b2(const char *a, ...) __attribute__((format(printf0, 1, 1)));    // expected-error {{'format' attribute parameter 3 is out of bounds}}42void c2(const char *a, ...) __attribute__((format(printf0, 0, 2)));    // expected-error {{'format' attribute parameter 2 is out of bounds}}43void d2(const char *a, int c) __attribute__((format(printf0, 1, 2)));  // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}44void e2(char *str, int c, ...) __attribute__((format(printf0, 2, 3))); // expected-error {{format argument not a string type}}45 46// FreeBSD usage47#define __printf0like(fmt, va) __attribute__((__format__(__printf0__, fmt, va)))48void null(int i, const char *a, ...) __printf0like(2, 0); // no-error49void null(int i, const char *a, ...) {                    // expected-note{{passing argument to parameter 'a' here}}50  if (a)51    (void)0/* vprintf(...) would go here */;52}53 54void callnull(void){55  null(0,        0); // no error56  null(0, (char*)0); // no error57  null(0, (void*)0); // no error58  null(0,  (int*)0); // expected-error {{incompatible pointer types}}59}60 61// FreeBSD kernel extensions62void a3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1, 2)));    // no-error63void b3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1, 1)));    // expected-error {{'format' attribute parameter 3 is out of bounds}}64void c3(const char *a, ...) __attribute__((format(freebsd_kprintf, 0, 2)));    // expected-error {{'format' attribute parameter 2 is out of bounds}}65void d3(const char *a, int c) __attribute__((format(freebsd_kprintf, 1, 2)));  // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}66void e3(char *str, int c, ...) __attribute__((format(freebsd_kprintf, 2, 3))); // expected-error {{format argument not a string type}}67 68// PR447069int xx_vprintf(const char *, va_list);70 71const char *foo(const char *format) __attribute__((format_arg(1)));72 73void __attribute__((format(printf, 1, 0)))74foo2(const char *fmt, va_list va) {75  xx_vprintf(foo(fmt), va);76}77 78// PR654279extern void gcc_format(const char *, ...)80    __attribute__((__format__(__gcc_diag__, 1, 2)));81extern void gcc_cformat(const char *, ...)82    __attribute__((__format__(__gcc_cdiag__, 1, 2)));83extern void gcc_cxxformat(const char *, ...)84    __attribute__((__format__(__gcc_cxxdiag__, 1, 2)));85extern void gcc_tformat(const char *, ...)86    __attribute__((__format__(__gcc_tdiag__, 1, 2)));87 88const char *foo3(const char *format) __attribute__((format_arg("foo"))); // expected-error{{'format_arg' attribute requires parameter 1 to be an integer constant}}89 90void call_nonvariadic(void) {91  d3("%i", 123);92  d3("%d", 123);93  d3("%s", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}94}95 96__attribute__((format(printf, 1, 2)))97void forward_fixed(const char *fmt, _Bool b, char i, short j, int k, float l, double m) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}98  forward_fixed(fmt, b, i, j, k, l, m);99  a(fmt, b, i, j, k, l, m);100}101 102// OpenBSD103// same as format(printf(...))...104void a2(const char *a, ...) __attribute__((format(syslog, 1, 2)));    // no-error105void b2(const char *a, ...) __attribute__((format(syslog, 1, 1)));    // expected-error {{'format' attribute parameter 3 is out of bounds}}106void c2(const char *a, ...) __attribute__((format(syslog, 0, 2)));    // expected-error {{'format' attribute parameter 2 is out of bounds}}107void d2(const char *a, int c) __attribute__((format(syslog, 1, 2)));  // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}108void e2(char *str, int c, ...) __attribute__((format(syslog, 2, 3))); // expected-error {{format argument not a string type}}109 110// gnu_printf111// same as format(printf(...))...112void a2(const char *a, ...) __attribute__((format(gnu_printf, 1, 2)));    // no-error113void b2(const char *a, ...) __attribute__((format(gnu_printf, 1, 1)));    // expected-error {{'format' attribute parameter 3 is out of bounds}}114void c2(const char *a, ...) __attribute__((format(gnu_printf, 0, 2)));    // expected-error {{'format' attribute parameter 2 is out of bounds}}115void d2(const char *a, int c) __attribute__((format(gnu_printf, 1, 2)));  // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}116void e2(char *str, int c, ...) __attribute__((format(gnu_printf, 2, 3))); // expected-error {{format argument not a string type}}117