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