diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-06-30 00:31:21 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-06-30 00:31:21 +0000 |
commit | 3e038b9d4bbcda05f1647a519494600f6c5b39f2 (patch) | |
tree | 8a17e7fe4aba72658d0e9aef9464d1878f0b087b /gcc/testsuite/gcc.dg/format | |
parent | 6c60929087b2ef567ada42c08c6ba2321610d599 (diff) | |
download | gcc-3e038b9d4bbcda05f1647a519494600f6c5b39f2.tar.gz |
gcc:
* builtin-attrs.def (gcc_diag, gcc_cdiag, gcc_cxxdiag): New
format attributes.
* c-format.c (enum format_type): Add gcc_diag_format_type,
gcc_cdiag_format_type, and gcc_cxxdiag_format_type.
(gcc_diag_length_specs, gcc_cdiag_length_specs,
gcc_cxxdiag_length_specs, gcc_diag_flag_pairs,
gcc_cdiag_flag_pairs, gcc_cxxdiag_flag_pairs, gcc_diag_flag_specs,
gcc_cdiag_flag_specs, gcc_cxxdiag_flag_specs, gcc_diag_char_table,
gcc_cdiag_char_table, gcc_cxxdiag_char_table): New.
(format_types_orig): Add new data.
(find_char_info_specifier_index, init_dynamic_diag_info): New
functions.
(handle_format_attribute): Update to handle new format attributes.
testsuite:
* gcc.dg/format/gcc_diag-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@68689 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/format')
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-1.c | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-1.c b/gcc/testsuite/gcc.dg/format/gcc_diag-1.c new file mode 100644 index 00000000000..7cf18c1b15f --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-1.c @@ -0,0 +1,185 @@ +/* Test for GCC diagnositc formats. */ +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +#define ATTRIBUTE_DIAG(F) __attribute__ ((__format__ (F, 1, 2))) __attribute__ ((__nonnull__)); + +/* Magic identifiers must be set before the attribute is used. */ + +typedef long long __gcc_host_wide_int__; + +typedef struct location_s +{ + const char *file; + int line; +} location_t; + +union tree_node; +typedef union tree_node *tree; + +extern int diag (const char *, ...) ATTRIBUTE_DIAG(__gcc_diag__); +extern int cdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cdiag__); +extern int cxxdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cxxdiag__); + +void +foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, + int *n, short int *hn, long int l, unsigned long int ul, + long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll, + ullong ull, unsigned int *un, const int *cn, signed char *ss, + unsigned char *us, const signed char *css, unsigned int u1, + unsigned int u2, location_t *loc, tree t1, union tree_node *t2, + tree *t3, tree t4[]) +{ + /* Acceptable C90 specifiers, flags and modifiers. */ + diag ("%%"); + cdiag ("%%"); + cxxdiag ("%%"); + diag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + cdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + cxxdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + diag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + cdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + cxxdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + diag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + cdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + cxxdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + diag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + cdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + cxxdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + diag ("%.*s", i, s); + cdiag ("%.*s", i, s); + cxxdiag ("%.*s", i, s); + + /* Extensions provided in the diagnostic framework. */ + diag ("%m"); + cdiag ("%m"); + cxxdiag ("%m"); + diag ("%H", loc); + cdiag ("%H", loc); + cxxdiag ("%H", loc); + + cdiag ("%D%F%T", t1, t1, t1); + cdiag ("%D%D%D%D", t1, t2, *t3, t4[5]); + cxxdiag ("%A%D%E%F%T%V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%D%D%D%D", t1, t2, *t3, t4[5]); + cxxdiag ("%#A%#D%#E%#F%#T%#V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%+A%+D%+E%+F%+T%+V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%+#A%+#D%+#E%+#F%+#T%+#V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%C%L%O%P%Q", i, i, i, i, i); + + /* Bad stuff with extensions. */ + diag ("%m", i); /* { dg-warning "format" "extra arg" } */ + cdiag ("%m", i); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%m", i); /* { dg-warning "format" "extra arg" } */ + diag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + diag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + diag ("%H"); /* { dg-warning "format" "missing arg" } */ + cdiag ("%H"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%H"); /* { dg-warning "format" "missing arg" } */ + diag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + diag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + diag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + diag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + diag ("%D", t1); /* { dg-warning "format" "bogus tree" } */ + cdiag ("%A", t1); /* { dg-warning "format" "bogus tree" } */ + cdiag ("%#D", t1); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+D", t1); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%C"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%C", l); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%C", i, i); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%#C", i); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+C", i); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%D"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%D"); /* { dg-warning "format" "missing arg" } */ + cdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */ + + /* Standard specifiers not accepted in the diagnostic framework. */ + diag ("%X\n", u); /* { dg-warning "format" "HEX" } */ + diag ("%f\n", d); /* { dg-warning "format" "float" } */ + diag ("%e\n", d); /* { dg-warning "format" "float" } */ + diag ("%E\n", d); /* { dg-warning "format" "float" } */ + diag ("%g\n", d); /* { dg-warning "format" "float" } */ + diag ("%G\n", d); /* { dg-warning "format" "float" } */ + diag ("%n\n", n); /* { dg-warning "format" "counter" } */ + diag ("%hd\n", i); /* { dg-warning "format" "conversion" } */ + + /* Various tests of bad argument types. */ + diag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + diag ("% d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("% d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("% d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + cdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + diag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + cdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + diag ("%d %lu\n", i, ul); + diag ("%d", l); /* { dg-warning "format" "bad argument types" } */ + diag ("%wd", l); /* { dg-warning "format" "bad argument types" } */ + diag ("%d", ll); /* { dg-warning "format" "bad argument types" } */ + diag ("%*s", i, s); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*.*s", i, i, s); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*d\n", i1, i); /* { dg-warning "format" "bad * argument types" } */ + diag ("%.*d\n", i2, i); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*.*ld\n", i1, i2, l); /* { dg-warning "format" "bad * argument types" } */ + diag ("%ld", i); /* { dg-warning "format" "bad argument types" } */ + diag ("%s", n); /* { dg-warning "format" "bad argument types" } */ + + /* Wrong number of arguments. */ + diag ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */ + diag ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */ + /* Miscellaneous bogus constructions. */ + diag (""); /* { dg-warning "zero-length" "warning for empty format" } */ + diag ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ + diag ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */ + diag ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ + diag (NULL); /* { dg-warning "null" "null format string warning" } */ + diag ("%"); /* { dg-warning "trailing" "trailing % warning" } */ + diag ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ + diag ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ + + /* Make sure we still get warnings for regular printf. */ + printf ("%d\n", ll); /* { dg-warning "format" "bad argument types" } */ +} |