On Mon, Feb 12, 2024 at 04:10:33PM +0000, Joseph Myers wrote: > On Sat, 10 Feb 2024, Jakub Jelinek wrote: > > > * c-format.cc (gcc_diag_length_specs): Add t and z modifiers. > > (PP_FORMAT_CHAR_TABLE, gcc_gfc_char_table): Add entries for t and > > z modifiers. > > Please also add some tests of format checking for these modifiers in > gcc.dg/format/gcc_*.c.
The following patch does that. Haven't added tests for bad type (but I think we don't have them in c99-printf* either) for these because it is hard to figure out what type from {,unsigned }{int,long,long long} size_t/ptrdiff_t certainly is not, guess one could do that with preprocessor conditionals, e.g. comparing __PTRDIFF_MAX__ with __INT_MAX__, __LONG_MAX__ and __LONG_LONG_MAX__ and pick up the one which is different; but we'd need to find out corresponding effective targets for the expected diagnostics. Tested on x86_64-linux and i686-linux, ok for trunk? 2024-02-13 Jakub Jelinek <ja...@redhat.com> * gcc.dg/format/gcc_diag-1.c (foo): Add tests for z and t modifiers. * gcc.dg/format/gcc_gfc-1.c (foo): Add tests for ll, z and t modifiers. --- gcc/testsuite/gcc.dg/format/gcc_diag-1.c.jj 2020-01-12 11:54:37.423398171 +0100 +++ gcc/testsuite/gcc.dg/format/gcc_diag-1.c 2024-02-12 19:41:55.512559836 +0100 @@ -33,7 +33,8 @@ foo (int i, int i1, int i2, unsigned int 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[], int *v, unsigned v_len) + tree *t3, tree t4[], int *v, unsigned v_len, size_t sz, ptrdiff_t pd, + ssize_t ssz, unsigned_ptrdiff_t upd) { /* Acceptable C90 specifiers, flags and modifiers. */ diag ("%%"); @@ -66,6 +67,16 @@ foo (int i, int i1, int i2, unsigned int cdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); cxxdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); dump ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + diag ("%zd%zi%zo%zu%zx", ssz, ssz, sz, sz, sz); + tdiag ("%zd%zi%zo%zu%zx", ssz, ssz, sz, sz, sz); + cdiag ("%zd%zi%zo%zu%zx", ssz, ssz, sz, sz, sz); + cxxdiag ("%zd%zi%zo%zu%zx", ssz, ssz, sz, sz, sz); + dump ("%zd%zi%zo%zu%zx", ssz, ssz, sz, sz, sz); + diag ("%td%ti%to%tu%tx", pd, pd, upd, upd, upd); + tdiag ("%td%ti%to%tu%tx", pd, pd, upd, upd, upd); + cdiag ("%td%ti%to%tu%tx", pd, pd, upd, upd, upd); + cxxdiag ("%td%ti%to%tu%tx", pd, pd, upd, upd, upd); + dump ("%td%ti%to%tu%tx", pd, pd, upd, upd, upd); diag ("%.*s", i, s); tdiag ("%.*s", i, s); cdiag ("%.*s", i, s); --- gcc/testsuite/gcc.dg/format/gcc_gfc-1.c.jj 2020-01-11 16:31:55.136291982 +0100 +++ gcc/testsuite/gcc.dg/format/gcc_gfc-1.c 2024-02-12 19:46:26.139775018 +0100 @@ -12,13 +12,19 @@ extern int gfc_warn (const char *, ...) void foo (unsigned int u, int i, char *s, unsigned long int ul, long int l, - llong ll, locus *loc) + llong ll, unsigned long long int ull, locus *loc, size_t sz, + ptrdiff_t pd, ssize_t ssz, unsigned_ptrdiff_t upd) { /* Acceptable C90 specifiers, flags and modifiers. */ gfc_warn ("%%"); gfc_warn ("%u%d%i%c%s%%", u, i, i, i, s); gfc_warn ("%lu%ld%li%%", ul, l, l); + /* Acceptable C99 specifiers, flags and modifiers. */ + gfc_warn ("%llu%lld%lli%%", ull, ll, ll); + gfc_warn ("%zu%zd%zi%%", sz, ssz, ssz); + gfc_warn ("%tu%td%ti%%", upd, pd, pd); + /* Extensions provided in gfc_warn. */ gfc_warn ("%C"); gfc_warn ("%L", loc); Jakub