1139825Simp/* Test for asm_fprintf formats. */ 21541Srgrimes/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ 31549Srgrimes/* { dg-do compile } */ 41549Srgrimes/* { dg-options "-Wformat" } */ 59507Sdg 69507Sdg#include "format.h" 71541Srgrimes 81541Srgrimes/* Magic identifier must be set before the attribute is used. */ 91541Srgrimestypedef long long __gcc_host_wide_int__; 101541Srgrimes 111541Srgrimesextern int asm_fprintf (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))) __attribute__ ((__nonnull__)); 121541Srgrimes 131541Srgrimesvoid 141541Srgrimesfoo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, 151541Srgrimes int *n, short int *hn, long int l, unsigned long int ul, 161541Srgrimes long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll, 171541Srgrimes ullong ull, unsigned int *un, const int *cn, signed char *ss, 181541Srgrimes unsigned char *us, const signed char *css, unsigned int u1, 191541Srgrimes unsigned int u2) 201541Srgrimes{ 2158705Scharnier /* Acceptable C90 specifiers, flags and modifiers. */ 221541Srgrimes asm_fprintf ("%%"); 231541Srgrimes asm_fprintf ("%d%i%o%u%x%X%c%s%%", i, i, u, u, u, u, i, s); 241541Srgrimes asm_fprintf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul); 251541Srgrimes asm_fprintf ("%lld%lli%llo%llu%llx%llX", ll, ll, ull, ull, ull, ull); 261541Srgrimes asm_fprintf ("%-d%-i%-o%-u%-x%-X%-c%-s", i, i, u, u, u, u, i, s); 271541Srgrimes asm_fprintf ("% d% i\n", i, i); 281541Srgrimes asm_fprintf ("%#o%#x%#X", u, u, u); 291541Srgrimes asm_fprintf ("%08d%08i%08o%08u%08x%08X", i, i, u, u, u, u); 301541Srgrimes asm_fprintf ("%d\n", i); 311541Srgrimes asm_fprintf ("%+d\n", i); 321541Srgrimes asm_fprintf ("%3d\n", i); 331541Srgrimes asm_fprintf ("%-3d\n", i); 341541Srgrimes asm_fprintf ("%.7d\n", i); 351541Srgrimes asm_fprintf ("%+9.4d\n", i); 361541Srgrimes asm_fprintf ("%.3ld\n", l); 371541Srgrimes asm_fprintf ("%d %lu\n", i, ul); 381541Srgrimes 391541Srgrimes /* Extensions provided in asm_fprintf. */ 401549Srgrimes asm_fprintf ("%O%R%I%L%U%@"); 411541Srgrimes asm_fprintf ("%r", i); 421541Srgrimes asm_fprintf ("%wd%wi%wo%wu%wx%wX", ll, ll, ull, ull, ull, ull); 431541Srgrimes 441541Srgrimes /* Standard specifiers not accepted in asm_fprintf. */ 451541Srgrimes asm_fprintf ("%f\n", d); /* { dg-warning "16:format" "float" } */ 461541Srgrimes asm_fprintf ("%e\n", d); /* { dg-warning "16:format" "float" } */ 471549Srgrimes asm_fprintf ("%E\n", d); /* { dg-warning "16:format" "float" } */ 481549Srgrimes asm_fprintf ("%g\n", d); /* { dg-warning "16:format" "float" } */ 499507Sdg asm_fprintf ("%G\n", d); /* { dg-warning "16:format" "float" } */ 507695Sdg asm_fprintf ("%p\n", p); /* { dg-warning "16:format" "pointer" } */ 511549Srgrimes asm_fprintf ("%n\n", n); /* { dg-warning "16:format" "counter" } */ 521549Srgrimes asm_fprintf ("%hd\n", i); /* { dg-warning "16:format" "conversion" } */ 53116226Sobrien 54116226Sobrien /* Various tests of bad argument types. */ 55116226Sobrien asm_fprintf ("%d", l); /* { dg-warning "16:format" "bad argument types" } */ 561541Srgrimes asm_fprintf ("%wd", l); /* { dg-warning "16:format" "bad argument types" } */ 571541Srgrimes asm_fprintf ("%d", ll); /* { dg-warning "16:format" "bad argument types" } */ 581541Srgrimes asm_fprintf ("%*d\n", i1, i); /* { dg-warning "16:format" "bad * argument types" } */ 591541Srgrimes asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "16:format" "bad * argument types" } */ 601541Srgrimes asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "16:format" "bad * argument types" } */ 6160041Sphk asm_fprintf ("%ld", i); /* { dg-warning "16:format" "bad argument types" } */ 629507Sdg asm_fprintf ("%s", n); /* { dg-warning "16:format" "bad argument types" } */ 6312662Sdg 64140767Sphk /* Wrong number of arguments. */ 6551340Sdillon asm_fprintf ("%d%d", i); /* { dg-warning "16:matching" "wrong number of args" } */ 66127926Salc asm_fprintf ("%d", i, i); /* { dg-warning "16:arguments" "wrong number of args" } */ 671541Srgrimes /* Miscellaneous bogus constructions. */ 68148875Sssouhlal asm_fprintf (""); /* { dg-warning "16:zero-length" "warning for empty format" } */ 69148875Sssouhlal asm_fprintf ("\0"); /* { dg-warning "16:embedded" "warning for embedded NUL" } */ 701541Srgrimes asm_fprintf ("%d\0", i); /* { dg-warning "16:embedded" "warning for embedded NUL" } */ 7112662Sdg asm_fprintf ("%d\0%d", i, i); /* { dg-warning "16:embedded|too many" "warning for embedded NUL" } */ 721541Srgrimes asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */ 739507Sdg asm_fprintf ("%"); /* { dg-warning "16:trailing" "trailing % warning" } */ 7431853Sdyson asm_fprintf ("%++d", i); /* { dg-warning "16:repeated" "repeated flag warning" } */ 751541Srgrimes asm_fprintf ((const char *)L"foo"); /* { dg-warning "30:wide" "wide string" } */ 7612662Sdg asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ 771541Srgrimes 78163359Salc /* Make sure we still get warnings for regular printf. */ 79163359Salc printf ("%d\n", ll); /* { dg-warning "11:format" "bad argument types" } */ 8092727Salfred} 8192727Salfred