| 1 |
// Test of -Wformat for GCC-specific formats |
| 2 |
// Copy of gcc.dg/format/gcc_diag-10.c, with class pp_element added. |
| 3 |
// { dg-do compile } |
| 4 |
// { dg-options "-Wformat" } |
| 5 |
|
| 6 |
/* Magic identifiers must be set before the attribute is used. */ |
| 7 |
|
| 8 |
typedef long long __gcc_host_wide_int__; |
| 9 |
|
| 10 |
typedef struct location_s |
| 11 |
{ |
| 12 |
const char *file; |
| 13 |
int line; |
| 14 |
} location_t; |
| 15 |
|
| 16 |
union tree_node; |
| 17 |
typedef union tree_node *tree; |
| 18 |
|
| 19 |
/* Define gimple as a dummy type. The typedef must be provided for |
| 20 |
the C test to find the symbol. */ |
| 21 |
typedef struct gimple gimple; |
| 22 |
|
| 23 |
/* Likewise for gimple. */ |
| 24 |
typedef struct cgraph_node cgraph_node; |
| 25 |
|
| 26 |
/* Likewise for diagnostic_event_id_t. */ |
| 27 |
typedef struct diagnostic_event_id_t diagnostic_event_id_t; |
| 28 |
|
| 29 |
namespace pp_markup { class element; } |
| 30 |
typedef pp_markup::element pp_element; |
| 31 |
|
| 32 |
#define FORMAT(kind) __attribute__ ((format (__gcc_## kind ##__, 1, 2))) |
| 33 |
|
| 34 |
void diag (const char*, ...) FORMAT (diag); |
| 35 |
void cdiag (const char*, ...) FORMAT (cdiag); |
| 36 |
void tdiag (const char*, ...) FORMAT (tdiag); |
| 37 |
void cxxdiag (const char*, ...) FORMAT (cxxdiag); |
| 38 |
void dump (const char*, ...) FORMAT (dump_printf); |
| 39 |
|
| 40 |
void test_diag (tree t, gimple *gc, diagnostic_event_id_t *event_id_ptr, |
| 41 |
pp_element *elem) |
| 42 |
{ |
| 43 |
diag ("%<"); /* { dg-warning "unterminated quoting directive" } */ |
| 44 |
diag ("%>"); /* { dg-warning "unmatched quoting directive " } */ |
| 45 |
diag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ |
| 46 |
|
| 47 |
diag ("%G", gc); /* { dg-warning "format" } */ |
| 48 |
diag ("%K", t); /* { dg-warning "format" } */ |
| 49 |
diag ("%@", event_id_ptr); |
| 50 |
|
| 51 |
diag ("%R"); /* { dg-warning "unmatched color reset directive" } */ |
| 52 |
diag ("%r", ""); /* { dg-warning "unterminated color directive" } */ |
| 53 |
diag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ |
| 54 |
diag ("%r%R", ""); |
| 55 |
diag ("%r%r%R", "", ""); |
| 56 |
diag ("%r%R%r%R", "", ""); |
| 57 |
|
| 58 |
diag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ |
| 59 |
diag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ |
| 60 |
diag ("%<%r%R%>", ""); |
| 61 |
|
| 62 |
diag ("%e", elem); |
| 63 |
diag ("%e", 42); /* { dg-warning "format" } */ |
| 64 |
} |
| 65 |
|
| 66 |
void test_cdiag (tree t, gimple *gc) |
| 67 |
{ |
| 68 |
cdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */ |
| 69 |
cdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */ |
| 70 |
cdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ |
| 71 |
|
| 72 |
cdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ |
| 73 |
cdiag ("%E", t); |
| 74 |
cdiag ("%F", t); /* { dg-warning ".F. conversion used unquoted" } */ |
| 75 |
cdiag ("%G", gc); /* { dg-warning "format" } */ |
| 76 |
cdiag ("%K", t); /* { dg-warning "format" } */ |
| 77 |
|
| 78 |
cdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ |
| 79 |
cdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ |
| 80 |
cdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ |
| 81 |
cdiag ("%r%R", ""); |
| 82 |
cdiag ("%r%r%R", "", ""); |
| 83 |
cdiag ("%r%R%r%R", "", ""); |
| 84 |
|
| 85 |
cdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ |
| 86 |
cdiag ("%V", t); /* { dg-warning ".V. conversion used unquoted" } */ |
| 87 |
|
| 88 |
cdiag ("%<%D%>", t); |
| 89 |
cdiag ("%<%E%>", t); |
| 90 |
cdiag ("%<%F%>", t); |
| 91 |
cdiag ("%<%G%>", gc); /* { dg-warning "format" } */ |
| 92 |
cdiag ("%<%K%>", t); /* { dg-warning "format" } */ |
| 93 |
|
| 94 |
cdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ |
| 95 |
cdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ |
| 96 |
cdiag ("%<%r%R%>", ""); |
| 97 |
|
| 98 |
cdiag ("%<%T%>", t); |
| 99 |
cdiag ("%<%V%>", t); |
| 100 |
|
| 101 |
cdiag ("%<%qD%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 102 |
cdiag ("%<%qE%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 103 |
cdiag ("%<%qT%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 104 |
} |
| 105 |
|
| 106 |
void test_tdiag (tree t, gimple *gc) |
| 107 |
{ |
| 108 |
tdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */ |
| 109 |
tdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */ |
| 110 |
tdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ |
| 111 |
|
| 112 |
tdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ |
| 113 |
tdiag ("%E", t); |
| 114 |
tdiag ("%G", gc); /* { dg-warning "format" } */ |
| 115 |
tdiag ("%K", t); /* { dg-warning "format" } */ |
| 116 |
|
| 117 |
tdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ |
| 118 |
tdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ |
| 119 |
tdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ |
| 120 |
tdiag ("%r%R", ""); |
| 121 |
tdiag ("%r%R", ""); |
| 122 |
tdiag ("%r%r%R", "", ""); |
| 123 |
tdiag ("%r%R%r%R", "", ""); |
| 124 |
|
| 125 |
tdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ |
| 126 |
|
| 127 |
tdiag ("%<%D%>", t); |
| 128 |
tdiag ("%<%E%>", t); |
| 129 |
tdiag ("%<%G%>", gc); /* { dg-warning "format" } */ |
| 130 |
tdiag ("%<%K%>", t); /* { dg-warning "format" } */ |
| 131 |
|
| 132 |
tdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ |
| 133 |
tdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ |
| 134 |
tdiag ("%<%r%R%>", ""); |
| 135 |
|
| 136 |
tdiag ("%<%T%>", t); |
| 137 |
|
| 138 |
tdiag ("%<%qD%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 139 |
tdiag ("%<%qE%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 140 |
tdiag ("%<%qT%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ |
| 141 |
} |
| 142 |
|
| 143 |
void test_cxxdiag (tree t, gimple *gc) |
| 144 |
{ |
| 145 |
cxxdiag ("%A", t); /* { dg-warning ".A. conversion used unquoted" } */ |
| 146 |
cxxdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ |
| 147 |
cxxdiag ("%E", t); |
| 148 |
cxxdiag ("%F", t); /* { dg-warning ".F. conversion used unquoted" } */ |
| 149 |
cxxdiag ("%G", gc); /* { dg-warning "format" } */ |
| 150 |
cxxdiag ("%K", t); /* { dg-warning "format" } */ |
| 151 |
|
| 152 |
cxxdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ |
| 153 |
cxxdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ |
| 154 |
cxxdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ |
| 155 |
cxxdiag ("%r%R", ""); |
| 156 |
cxxdiag ("%r%R", ""); |
| 157 |
cxxdiag ("%r%r%R", "", ""); |
| 158 |
cxxdiag ("%r%R%r%R", "", ""); |
| 159 |
|
| 160 |
cxxdiag ("%S", t); /* { dg-warning ".S. conversion used unquoted" } */ |
| 161 |
cxxdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ |
| 162 |
cxxdiag ("%V", t); /* { dg-warning ".V. conversion used unquoted" } */ |
| 163 |
cxxdiag ("%X", t); /* { dg-warning ".X. conversion used unquoted" } */ |
| 164 |
|
| 165 |
cxxdiag ("%<%A%>", t); |
| 166 |
cxxdiag ("%<%D%>", t); |
| 167 |
cxxdiag ("%<%E%>", t); |
| 168 |
cxxdiag ("%<%F%>", t); |
| 169 |
cxxdiag ("%<%R%>"); /* { dg-warning "unmatched color reset" } */ |
| 170 |
cxxdiag ("%<%r%R%>", ""); |
| 171 |
cxxdiag ("%<%S%>", t); |
| 172 |
cxxdiag ("%<%T%>", t); |
| 173 |
cxxdiag ("%<%V%>", t); |
| 174 |
cxxdiag ("%<%X%>", t); |
| 175 |
} |
| 176 |
|
| 177 |
void test_dump (tree t, gimple *stmt, cgraph_node *node) |
| 178 |
{ |
| 179 |
dump ("%<"); /* { dg-warning "unterminated quoting directive" } */ |
| 180 |
dump ("%>"); /* { dg-warning "unmatched quoting directive " } */ |
| 181 |
dump ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ |
| 182 |
|
| 183 |
dump ("%R"); /* { dg-warning "unmatched color reset directive" } */ |
| 184 |
dump ("%r", ""); /* { dg-warning "unterminated color directive" } */ |
| 185 |
dump ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ |
| 186 |
dump ("%r%R", ""); |
| 187 |
dump ("%r%r%R", "", ""); |
| 188 |
dump ("%r%R%r%R", "", ""); |
| 189 |
|
| 190 |
dump ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ |
| 191 |
dump ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ |
| 192 |
dump ("%<%r%R%>", ""); |
| 193 |
|
| 194 |
dump ("%E", stmt); |
| 195 |
dump ("%T", t); |
| 196 |
dump ("%G", stmt); |
| 197 |
dump ("%C", node); |
| 198 |
dump ("%f", 1.0); |
| 199 |
dump ("%4.2f", 1.0); /* { dg-warning "format" } */ |
| 200 |
} |