1  /* Test for asm_fprintf formats.  */
       2  /* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
       3  /* { dg-do compile } */
       4  /* { dg-options "-Wformat" } */
       5  
       6  #include "format.h"
       7  
       8  /* Magic identifier must be set before the attribute is used.  */
       9  typedef long long __gcc_host_wide_int__;
      10  
      11  extern int asm_fprintf (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))) __attribute__ ((__nonnull__));
      12  
      13  void
      14  foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
      15       int *n, short int *hn, long int l, unsigned long int ul,
      16       long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll,
      17       ullong ull, unsigned int *un, const int *cn, signed char *ss,
      18       unsigned char *us, const signed char *css, unsigned int u1,
      19       unsigned int u2)
      20  {
      21    /* Acceptable C90 specifiers, flags and modifiers.  */
      22    asm_fprintf ("%%");
      23    asm_fprintf ("%d%i%o%u%x%X%c%s%%", i, i, u, u, u, u, i, s);
      24    asm_fprintf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul);
      25    asm_fprintf ("%lld%lli%llo%llu%llx%llX", ll, ll, ull, ull, ull, ull);
      26    asm_fprintf ("%-d%-i%-o%-u%-x%-X%-c%-s", i, i, u, u, u, u, i, s);
      27    asm_fprintf ("% d% i\n", i, i);
      28    asm_fprintf ("%#o%#x%#X", u, u, u);
      29    asm_fprintf ("%08d%08i%08o%08u%08x%08X", i, i, u, u, u, u);
      30    asm_fprintf ("%d\n", i);
      31    asm_fprintf ("%+d\n", i);
      32    asm_fprintf ("%3d\n", i);
      33    asm_fprintf ("%-3d\n", i);
      34    asm_fprintf ("%.7d\n", i);
      35    asm_fprintf ("%+9.4d\n", i);
      36    asm_fprintf ("%.3ld\n", l);
      37    asm_fprintf ("%d %lu\n", i, ul);
      38  
      39    /* Extensions provided in asm_fprintf.  */
      40    asm_fprintf ("%O%R%I%L%U%@");
      41    asm_fprintf ("%r", i);
      42    asm_fprintf ("%wd%wi%wo%wu%wx%wX", ll, ll, ull, ull, ull, ull);
      43  
      44    /* Standard specifiers not accepted in asm_fprintf.  */
      45    asm_fprintf ("%f\n", d); /* { dg-warning "18:format" "float" } */
      46    asm_fprintf ("%e\n", d); /* { dg-warning "18:format" "float" } */
      47    asm_fprintf ("%E\n", d); /* { dg-warning "18:format" "float" } */
      48    asm_fprintf ("%g\n", d); /* { dg-warning "18:format" "float" } */
      49    asm_fprintf ("%G\n", d); /* { dg-warning "18:format" "float" } */
      50    asm_fprintf ("%p\n", p); /* { dg-warning "18:format" "pointer" } */
      51    asm_fprintf ("%n\n", n); /* { dg-warning "18:format" "counter" } */
      52    asm_fprintf ("%hd\n", i); /* { dg-warning "18:format" "conversion" } */
      53  
      54    /* Various tests of bad argument types.  */
      55    asm_fprintf ("%d", l); /* { dg-warning "18:format" "bad argument types" } */
      56    asm_fprintf ("%wd", l); /* { dg-warning "19:format" "bad argument types" } */
      57    asm_fprintf ("%d", ll); /* { dg-warning "18:format" "bad argument types" } */
      58    asm_fprintf ("%*d\n", i1, i); /* { dg-warning "18:format" "bad * argument types" } */
      59    asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "19:format" "bad * argument types" } */
      60    asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "18:format" "bad * argument types" } */
      61    asm_fprintf ("%ld", i); /* { dg-warning "19:format" "bad argument types" } */
      62    asm_fprintf ("%s", n); /* { dg-warning "18:format" "bad argument types" } */
      63  
      64    /* Wrong number of arguments.  */
      65    asm_fprintf ("%d%d", i); /* { dg-warning "20:matching" "wrong number of args" } */
      66    asm_fprintf ("%d", i, i); /* { dg-warning "16:arguments" "wrong number of args" } */
      67    /* Miscellaneous bogus constructions.  */
      68    asm_fprintf (""); /* { dg-warning "16:zero-length" "warning for empty format" } */
      69    asm_fprintf ("\0"); /* { dg-warning "17:embedded" "warning for embedded NUL" } */
      70    asm_fprintf ("%d\0", i); /* { dg-warning "19:embedded" "warning for embedded NUL" } */
      71    asm_fprintf ("%d\0%d", i, i); /* { dg-warning "19:embedded|too many" "warning for embedded NUL" } */
      72    asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */
      73    asm_fprintf ("%"); /* { dg-warning "17:trailing" "trailing % warning" } */
      74    asm_fprintf ("%++d", i); /* { dg-warning "19:repeated" "repeated flag warning" } */
      75    asm_fprintf ((const char *)L"foo"); /* { dg-warning "30:wide" "wide string" } */
      76    asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */
      77  
      78    /* Make sure we still get warnings for regular printf.  */
      79    printf ("%d\n", ll); /* { dg-warning "13:format" "bad argument types" } */
      80  }
      81  /* { dg-warning "16:too many arguments for format" "too many arguments" { target *-*-* } 0 } */