1 /* Check calls to formatted I/O functions (-Wformat).
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
25 #include "stringpool.h"
30 #include "diagnostic-core.h"
31 #include "langhooks.h"
33 #include "alloc-pool.h"
36 /* Handle attributes associated with format checking. */
38 /* This must be in the same order as format_types, except for
39 format_type_error. Target-specific format types do not have
40 matching enum values. */
41 enum format_type
{ printf_format_type
, asm_fprintf_format_type
,
42 gcc_diag_format_type
, gcc_tdiag_format_type
,
43 gcc_cdiag_format_type
,
44 gcc_cxxdiag_format_type
, gcc_gfc_format_type
,
45 gcc_objc_string_format_type
,
46 format_type_error
= -1};
48 typedef struct function_format_info
50 int format_type
; /* type of format (printf, scanf, etc.) */
51 unsigned HOST_WIDE_INT format_num
; /* number of format argument */
52 unsigned HOST_WIDE_INT first_arg_num
; /* number of first arg (zero for varargs) */
53 } function_format_info
;
55 static bool decode_format_attr (tree
, function_format_info
*, int);
56 static int decode_format_type (const char *);
58 static bool check_format_string (tree argument
,
59 unsigned HOST_WIDE_INT format_num
,
60 int flags
, bool *no_add_attrs
,
61 int expected_format_type
);
62 static bool get_constant (tree expr
, unsigned HOST_WIDE_INT
*value
,
64 static const char *convert_format_name_to_system_name (const char *attr_name
);
65 static bool cmp_attribs (const char *tattr_name
, const char *attr_name
);
67 static int first_target_format_type
;
68 static const char *format_name (int format_num
);
69 static int format_flags (int format_num
);
71 /* Check that we have a pointer to a string suitable for use as a format.
72 The default is to check for a char type.
73 For objective-c dialects, this is extended to include references to string
74 objects validated by objc_string_ref_type_p ().
75 Targets may also provide a string object type that can be used within c and
76 c++ and shared with their respective objective-c dialects. In this case the
77 reference to a format string is checked for validity via a hook.
79 The function returns true if strref points to any string type valid for the
80 language dialect and target. */
83 valid_stringptr_type_p (tree strref
)
85 return (strref
!= NULL
86 && TREE_CODE (strref
) == POINTER_TYPE
87 && (TYPE_MAIN_VARIANT (TREE_TYPE (strref
)) == char_type_node
88 || objc_string_ref_type_p (strref
)
89 || (*targetcm
.string_object_ref_type_p
) ((const_tree
) strref
)));
92 /* Handle a "format_arg" attribute; arguments as in
93 struct attribute_spec.handler. */
95 handle_format_arg_attribute (tree
*node
, tree
ARG_UNUSED (name
),
96 tree args
, int flags
, bool *no_add_attrs
)
99 tree format_num_expr
= TREE_VALUE (args
);
100 unsigned HOST_WIDE_INT format_num
= 0;
102 if (!get_constant (format_num_expr
, &format_num
, 0))
104 error ("format string has invalid operand number");
105 *no_add_attrs
= true;
109 if (prototype_p (type
))
111 /* The format arg can be any string reference valid for the language and
112 target. We cannot be more specific in this case. */
113 if (!check_format_string (type
, format_num
, flags
, no_add_attrs
, -1))
117 if (!valid_stringptr_type_p (TREE_TYPE (type
)))
119 if (!(flags
& (int) ATTR_FLAG_BUILT_IN
))
120 error ("function does not return string type");
121 *no_add_attrs
= true;
128 /* Verify that the format_num argument is actually a string reference suitable,
129 for the language dialect and target (in case the format attribute is in
130 error). When we know the specific reference type expected, this is also
133 check_format_string (tree fntype
, unsigned HOST_WIDE_INT format_num
,
134 int flags
, bool *no_add_attrs
, int expected_format_type
)
136 unsigned HOST_WIDE_INT i
;
137 bool is_objc_sref
, is_target_sref
, is_char_ref
;
140 function_args_iterator iter
;
143 FOREACH_FUNCTION_ARGS (fntype
, ref
, iter
)
151 || !valid_stringptr_type_p (ref
))
153 if (!(flags
& (int) ATTR_FLAG_BUILT_IN
))
154 error ("format string argument is not a string type");
155 *no_add_attrs
= true;
159 /* We only know that we want a suitable string reference. */
160 if (expected_format_type
< 0)
163 /* Now check that the arg matches the expected type. */
165 (TYPE_MAIN_VARIANT (TREE_TYPE (ref
)) == char_type_node
);
167 fmt_flags
= format_flags (expected_format_type
);
168 is_objc_sref
= is_target_sref
= false;
170 is_objc_sref
= objc_string_ref_type_p (ref
);
172 if (!(fmt_flags
& FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL
))
175 return true; /* OK, we expected a char and found one. */
178 /* We expected a char but found an extended string type. */
180 error ("found a %<%s%> reference but the format argument should"
181 " be a string", format_name (gcc_objc_string_format_type
));
183 error ("found a %qT but the format argument should be a string",
185 *no_add_attrs
= true;
190 /* We expect a string object type as the format arg. */
193 error ("format argument should be a %<%s%> reference but"
194 " a string was found", format_name (expected_format_type
));
195 *no_add_attrs
= true;
199 /* We will assert that objective-c will support either its own string type
200 or the target-supplied variant. */
202 is_target_sref
= (*targetcm
.string_object_ref_type_p
) ((const_tree
) ref
);
204 if (expected_format_type
== (int) gcc_objc_string_format_type
205 && (is_objc_sref
|| is_target_sref
))
208 /* We will allow a target string ref to match only itself. */
209 if (first_target_format_type
210 && expected_format_type
>= first_target_format_type
215 error ("format argument should be a %<%s%> reference",
216 format_name (expected_format_type
));
217 *no_add_attrs
= true;
224 /* Verify EXPR is a constant, and store its value.
225 If validated_p is true there should be no errors.
226 Returns true on success, false otherwise. */
228 get_constant (tree expr
, unsigned HOST_WIDE_INT
*value
, int validated_p
)
230 if (TREE_CODE (expr
) != INTEGER_CST
|| TREE_INT_CST_HIGH (expr
) != 0)
232 gcc_assert (!validated_p
);
236 *value
= TREE_INT_CST_LOW (expr
);
241 /* Decode the arguments to a "format" attribute into a
242 function_format_info structure. It is already known that the list
243 is of the right length. If VALIDATED_P is true, then these
244 attributes have already been validated and must not be erroneous;
245 if false, it will give an error message. Returns true if the
246 attributes are successfully decoded, false otherwise. */
249 decode_format_attr (tree args
, function_format_info
*info
, int validated_p
)
251 tree format_type_id
= TREE_VALUE (args
);
252 tree format_num_expr
= TREE_VALUE (TREE_CHAIN (args
));
253 tree first_arg_num_expr
254 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
)));
256 if (TREE_CODE (format_type_id
) != IDENTIFIER_NODE
)
258 gcc_assert (!validated_p
);
259 error ("unrecognized format specifier");
264 const char *p
= IDENTIFIER_POINTER (format_type_id
);
266 p
= convert_format_name_to_system_name (p
);
268 info
->format_type
= decode_format_type (p
);
270 if (!c_dialect_objc ()
271 && info
->format_type
== gcc_objc_string_format_type
)
273 gcc_assert (!validated_p
);
274 warning (OPT_Wformat_
, "%qE is only allowed in Objective-C dialects",
276 info
->format_type
= format_type_error
;
280 if (info
->format_type
== format_type_error
)
282 gcc_assert (!validated_p
);
283 warning (OPT_Wformat_
, "%qE is an unrecognized format function type",
289 if (!get_constant (format_num_expr
, &info
->format_num
, validated_p
))
291 error ("format string has invalid operand number");
295 if (!get_constant (first_arg_num_expr
, &info
->first_arg_num
, validated_p
))
297 error ("%<...%> has invalid operand number");
301 if (info
->first_arg_num
!= 0 && info
->first_arg_num
<= info
->format_num
)
303 gcc_assert (!validated_p
);
304 error ("format string argument follows the args to be formatted");
311 /* Check a call to a format function against a parameter list. */
313 /* The C standard version C++ is treated as equivalent to
314 or inheriting from, for the purpose of format features supported. */
315 #define CPLUSPLUS_STD_VER (cxx_dialect < cxx11 ? STD_C94 : STD_C99)
316 /* The C standard version we are checking formats against when pedantic. */
317 #define C_STD_VER ((int) (c_dialect_cxx () \
318 ? CPLUSPLUS_STD_VER \
321 : (flag_isoc94 ? STD_C94 : STD_C89))))
322 /* The name to give to the standard version we are warning about when
323 pedantic. FEATURE_VER is the version in which the feature warned out
324 appeared, which is higher than C_STD_VER. */
325 #define C_STD_NAME(FEATURE_VER) (c_dialect_cxx () \
326 ? (cxx_dialect < cxx11 ? "ISO C++98" \
328 : ((FEATURE_VER) == STD_EXT \
331 /* Adjust a C standard version, which may be STD_C9L, to account for
332 -Wno-long-long. Returns other standard versions unchanged. */
333 #define ADJ_STD(VER) ((int) ((VER) == STD_C9L \
334 ? (warn_long_long ? STD_C99 : STD_C89) \
337 /* Enum describing the kind of specifiers present in the format and
338 requiring an argument. */
339 enum format_specifier_kind
{
342 CF_KIND_FIELD_PRECISION
345 static const char *kind_descriptions
[] = {
347 N_("field width specifier"),
348 N_("field precision specifier")
351 /* Structure describing details of a type expected in format checking,
352 and the type to check against it. */
353 typedef struct format_wanted_type
355 /* The type wanted. */
357 /* The name of this type to use in diagnostics. */
358 const char *wanted_type_name
;
359 /* Should be type checked just for scalar width identity. */
360 int scalar_identity_flag
;
361 /* The level of indirection through pointers at which this type occurs. */
363 /* Whether, when pointer_count is 1, to allow any character type when
364 pedantic, rather than just the character or void type specified. */
365 int char_lenient_flag
;
366 /* Whether the argument, dereferenced once, is written into and so the
367 argument must not be a pointer to a const-qualified type. */
369 /* Whether the argument, dereferenced once, is read from and so
370 must not be a NULL pointer. */
371 int reading_from_flag
;
372 /* The kind of specifier that this type is used for. */
373 enum format_specifier_kind kind
;
374 /* The starting character of the specifier. This never includes the
375 initial percent sign. */
376 const char *format_start
;
377 /* The length of the specifier. */
379 /* The actual parameter to check against the wanted type. */
381 /* The argument number of that parameter. */
383 /* The next type to check for this format conversion, or NULL if none. */
384 struct format_wanted_type
*next
;
385 } format_wanted_type
;
387 /* Convenience macro for format_length_info meaning unused. */
388 #define NO_FMT NULL, FMT_LEN_none, STD_C89
390 static const format_length_info printf_length_specs
[] =
392 { "h", FMT_LEN_h
, STD_C89
, "hh", FMT_LEN_hh
, STD_C99
, 0 },
393 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C9L
, 0 },
394 { "q", FMT_LEN_ll
, STD_EXT
, NO_FMT
, 0 },
395 { "L", FMT_LEN_L
, STD_C89
, NO_FMT
, 0 },
396 { "z", FMT_LEN_z
, STD_C99
, NO_FMT
, 0 },
397 { "Z", FMT_LEN_z
, STD_EXT
, NO_FMT
, 0 },
398 { "t", FMT_LEN_t
, STD_C99
, NO_FMT
, 0 },
399 { "j", FMT_LEN_j
, STD_C99
, NO_FMT
, 0 },
400 { "H", FMT_LEN_H
, STD_EXT
, NO_FMT
, 0 },
401 { "D", FMT_LEN_D
, STD_EXT
, "DD", FMT_LEN_DD
, STD_EXT
, 0 },
402 { NO_FMT
, NO_FMT
, 0 }
405 /* Length specifiers valid for asm_fprintf. */
406 static const format_length_info asm_fprintf_length_specs
[] =
408 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C89
, 0 },
409 { "w", FMT_LEN_none
, STD_C89
, NO_FMT
, 0 },
410 { NO_FMT
, NO_FMT
, 0 }
413 /* Length specifiers valid for GCC diagnostics. */
414 static const format_length_info gcc_diag_length_specs
[] =
416 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C89
, 0 },
417 { "w", FMT_LEN_none
, STD_C89
, NO_FMT
, 0 },
418 { NO_FMT
, NO_FMT
, 0 }
421 /* The custom diagnostics all accept the same length specifiers. */
422 #define gcc_tdiag_length_specs gcc_diag_length_specs
423 #define gcc_cdiag_length_specs gcc_diag_length_specs
424 #define gcc_cxxdiag_length_specs gcc_diag_length_specs
426 /* This differs from printf_length_specs only in that "Z" is not accepted. */
427 static const format_length_info scanf_length_specs
[] =
429 { "h", FMT_LEN_h
, STD_C89
, "hh", FMT_LEN_hh
, STD_C99
, 0 },
430 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C9L
, 0 },
431 { "q", FMT_LEN_ll
, STD_EXT
, NO_FMT
, 0 },
432 { "L", FMT_LEN_L
, STD_C89
, NO_FMT
, 0 },
433 { "z", FMT_LEN_z
, STD_C99
, NO_FMT
, 0 },
434 { "t", FMT_LEN_t
, STD_C99
, NO_FMT
, 0 },
435 { "j", FMT_LEN_j
, STD_C99
, NO_FMT
, 0 },
436 { "H", FMT_LEN_H
, STD_EXT
, NO_FMT
, 0 },
437 { "D", FMT_LEN_D
, STD_EXT
, "DD", FMT_LEN_DD
, STD_EXT
, 0 },
438 { NO_FMT
, NO_FMT
, 0 }
442 /* All tables for strfmon use STD_C89 everywhere, since -pedantic warnings
443 make no sense for a format type not part of any C standard version. */
444 static const format_length_info strfmon_length_specs
[] =
446 /* A GNU extension. */
447 { "L", FMT_LEN_L
, STD_C89
, NO_FMT
, 0 },
448 { NO_FMT
, NO_FMT
, 0 }
452 /* For now, the Fortran front-end routines only use l as length modifier. */
453 static const format_length_info gcc_gfc_length_specs
[] =
455 { "l", FMT_LEN_l
, STD_C89
, NO_FMT
, 0 },
456 { NO_FMT
, NO_FMT
, 0 }
460 static const format_flag_spec printf_flag_specs
[] =
462 { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89
},
463 { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89
},
464 { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89
},
465 { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89
},
466 { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89
},
467 { '\'', 0, 0, N_("''' flag"), N_("the ''' printf flag"), STD_EXT
},
468 { 'I', 0, 0, N_("'I' flag"), N_("the 'I' printf flag"), STD_EXT
},
469 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
470 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89
},
471 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
472 { 0, 0, 0, NULL
, NULL
, STD_C89
}
476 static const format_flag_pair printf_flag_pairs
[] =
480 { '0', 'p', 1, 'i' },
484 static const format_flag_spec asm_fprintf_flag_specs
[] =
486 { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89
},
487 { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89
},
488 { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89
},
489 { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89
},
490 { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89
},
491 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
492 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89
},
493 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
494 { 0, 0, 0, NULL
, NULL
, STD_C89
}
497 static const format_flag_pair asm_fprintf_flag_pairs
[] =
501 { '0', 'p', 1, 'i' },
505 static const format_flag_pair gcc_diag_flag_pairs
[] =
510 #define gcc_tdiag_flag_pairs gcc_diag_flag_pairs
511 #define gcc_cdiag_flag_pairs gcc_diag_flag_pairs
512 #define gcc_cxxdiag_flag_pairs gcc_diag_flag_pairs
514 static const format_flag_pair gcc_gfc_flag_pairs
[] =
519 static const format_flag_spec gcc_diag_flag_specs
[] =
521 { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89
},
522 { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89
},
523 { 'q', 0, 0, N_("'q' flag"), N_("the 'q' diagnostic flag"), STD_C89
},
524 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89
},
525 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
526 { 0, 0, 0, NULL
, NULL
, STD_C89
}
529 #define gcc_tdiag_flag_specs gcc_diag_flag_specs
530 #define gcc_cdiag_flag_specs gcc_diag_flag_specs
531 #define gcc_cxxdiag_flag_specs gcc_diag_flag_specs
533 static const format_flag_spec scanf_flag_specs
[] =
535 { '*', 0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89
},
536 { 'a', 0, 0, N_("'a' flag"), N_("the 'a' scanf flag"), STD_EXT
},
537 { 'm', 0, 0, N_("'m' flag"), N_("the 'm' scanf flag"), STD_EXT
},
538 { 'w', 0, 0, N_("field width"), N_("field width in scanf format"), STD_C89
},
539 { 'L', 0, 0, N_("length modifier"), N_("length modifier in scanf format"), STD_C89
},
540 { '\'', 0, 0, N_("''' flag"), N_("the ''' scanf flag"), STD_EXT
},
541 { 'I', 0, 0, N_("'I' flag"), N_("the 'I' scanf flag"), STD_EXT
},
542 { 0, 0, 0, NULL
, NULL
, STD_C89
}
546 static const format_flag_pair scanf_flag_pairs
[] =
554 static const format_flag_spec strftime_flag_specs
[] =
556 { '_', 0, 0, N_("'_' flag"), N_("the '_' strftime flag"), STD_EXT
},
557 { '-', 0, 0, N_("'-' flag"), N_("the '-' strftime flag"), STD_EXT
},
558 { '0', 0, 0, N_("'0' flag"), N_("the '0' strftime flag"), STD_EXT
},
559 { '^', 0, 0, N_("'^' flag"), N_("the '^' strftime flag"), STD_EXT
},
560 { '#', 0, 0, N_("'#' flag"), N_("the '#' strftime flag"), STD_EXT
},
561 { 'w', 0, 0, N_("field width"), N_("field width in strftime format"), STD_EXT
},
562 { 'E', 0, 0, N_("'E' modifier"), N_("the 'E' strftime modifier"), STD_C99
},
563 { 'O', 0, 0, N_("'O' modifier"), N_("the 'O' strftime modifier"), STD_C99
},
564 { 'O', 'o', 0, NULL
, N_("the 'O' modifier"), STD_EXT
},
565 { 0, 0, 0, NULL
, NULL
, STD_C89
}
569 static const format_flag_pair strftime_flag_pairs
[] =
580 static const format_flag_spec strfmon_flag_specs
[] =
582 { '=', 0, 1, N_("fill character"), N_("fill character in strfmon format"), STD_C89
},
583 { '^', 0, 0, N_("'^' flag"), N_("the '^' strfmon flag"), STD_C89
},
584 { '+', 0, 0, N_("'+' flag"), N_("the '+' strfmon flag"), STD_C89
},
585 { '(', 0, 0, N_("'(' flag"), N_("the '(' strfmon flag"), STD_C89
},
586 { '!', 0, 0, N_("'!' flag"), N_("the '!' strfmon flag"), STD_C89
},
587 { '-', 0, 0, N_("'-' flag"), N_("the '-' strfmon flag"), STD_C89
},
588 { 'w', 0, 0, N_("field width"), N_("field width in strfmon format"), STD_C89
},
589 { '#', 0, 0, N_("left precision"), N_("left precision in strfmon format"), STD_C89
},
590 { 'p', 0, 0, N_("right precision"), N_("right precision in strfmon format"), STD_C89
},
591 { 'L', 0, 0, N_("length modifier"), N_("length modifier in strfmon format"), STD_C89
},
592 { 0, 0, 0, NULL
, NULL
, STD_C89
}
595 static const format_flag_pair strfmon_flag_pairs
[] =
602 static const format_char_info print_char_table
[] =
604 /* C89 conversion specifiers. */
605 { "di", 0, STD_C89
, { T89_I
, T99_SC
, T89_S
, T89_L
, T9L_LL
, TEX_LL
, T99_SST
, T99_PD
, T99_IM
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +'I", "i", NULL
},
606 { "oxX", 0, STD_C89
, { T89_UI
, T99_UC
, T89_US
, T89_UL
, T9L_ULL
, TEX_ULL
, T99_ST
, T99_UPD
, T99_UIM
, BADLEN
, BADLEN
, BADLEN
}, "-wp0#", "i", NULL
},
607 { "u", 0, STD_C89
, { T89_UI
, T99_UC
, T89_US
, T89_UL
, T9L_ULL
, TEX_ULL
, T99_ST
, T99_UPD
, T99_UIM
, BADLEN
, BADLEN
, BADLEN
}, "-wp0'I", "i", NULL
},
608 { "fgG", 0, STD_C89
, { T89_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T89_LD
, BADLEN
, BADLEN
, BADLEN
, TEX_D32
, TEX_D64
, TEX_D128
}, "-wp0 +#'I", "", NULL
},
609 { "eE", 0, STD_C89
, { T89_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T89_LD
, BADLEN
, BADLEN
, BADLEN
, TEX_D32
, TEX_D64
, TEX_D128
}, "-wp0 +#I", "", NULL
},
610 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T94_WI
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "", NULL
},
611 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "cR", NULL
},
612 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "c", NULL
},
613 { "n", 1, STD_C89
, { T89_I
, T99_SC
, T89_S
, T89_L
, T9L_LL
, BADLEN
, T99_SST
, T99_PD
, T99_IM
, BADLEN
, BADLEN
, BADLEN
}, "", "W", NULL
},
614 /* C99 conversion specifiers. */
615 { "F", 0, STD_C99
, { T99_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T99_LD
, BADLEN
, BADLEN
, BADLEN
, TEX_D32
, TEX_D64
, TEX_D128
}, "-wp0 +#'I", "", NULL
},
616 { "aA", 0, STD_C99
, { T99_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T99_LD
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +#", "", NULL
},
617 /* X/Open conversion specifiers. */
618 { "C", 0, STD_EXT
, { TEX_WI
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "", NULL
},
619 { "S", 1, STD_EXT
, { TEX_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "R", NULL
},
620 /* GNU conversion specifiers. */
621 { "m", 0, STD_EXT
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "", NULL
},
622 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
625 static const format_char_info asm_fprintf_char_table
[] =
627 /* C89 conversion specifiers. */
628 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +", "i", NULL
},
629 { "oxX", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0#", "i", NULL
},
630 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0", "i", NULL
},
631 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "", NULL
},
632 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "cR", NULL
},
634 /* asm_fprintf conversion specifiers. */
635 { "O", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
636 { "R", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
637 { "I", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
638 { "L", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
639 { "U", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
640 { "r", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "", NULL
},
641 { "@", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
642 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
645 static const format_char_info gcc_diag_char_table
[] =
647 /* C89 conversion specifiers. */
648 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
649 { "ox", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
650 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
651 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
652 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "pq", "cR", NULL
},
653 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "c", NULL
},
655 /* Custom conversion specifiers. */
657 /* These will require a "tree" at runtime. */
658 { "K", 0, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
660 { "r", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
},
661 { "<>'R",0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
662 { "m", 0, STD_C89
, NOARGUMENTS
, "q", "", NULL
},
663 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
666 static const format_char_info gcc_tdiag_char_table
[] =
668 /* C89 conversion specifiers. */
669 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
670 { "ox", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
671 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
672 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
673 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "pq", "cR", NULL
},
674 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "c", NULL
},
676 /* Custom conversion specifiers. */
678 /* These will require a "tree" at runtime. */
679 { "DFKTEV", 0, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q+", "", NULL
},
681 { "v", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q#", "", NULL
},
683 { "r", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
},
684 { "<>'R",0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
685 { "m", 0, STD_C89
, NOARGUMENTS
, "q", "", NULL
},
686 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
689 static const format_char_info gcc_cdiag_char_table
[] =
691 /* C89 conversion specifiers. */
692 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
693 { "ox", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
694 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
695 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
696 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "pq", "cR", NULL
},
697 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "c", NULL
},
699 /* Custom conversion specifiers. */
701 /* These will require a "tree" at runtime. */
702 { "DEFKTV", 0, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q+", "", NULL
},
704 { "v", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q#", "", NULL
},
706 { "r", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
},
707 { "<>'R",0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
708 { "m", 0, STD_C89
, NOARGUMENTS
, "q", "", NULL
},
709 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
712 static const format_char_info gcc_cxxdiag_char_table
[] =
714 /* C89 conversion specifiers. */
715 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
716 { "ox", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
717 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
718 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
719 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "pq", "cR", NULL
},
720 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "c", NULL
},
722 /* Custom conversion specifiers. */
724 /* These will require a "tree" at runtime. */
725 { "ADEFKSTVX",0,STD_C89
,{ T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q+#", "", NULL
},
727 { "v", 0,STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q#", "", NULL
},
729 /* These accept either an 'int' or an 'enum tree_code' (which is handled as an 'int'.) */
730 { "CLOPQ",0,STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "q", "", NULL
},
732 { "r", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
},
733 { "<>'R",0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
734 { "m", 0, STD_C89
, NOARGUMENTS
, "q", "", NULL
},
735 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
738 static const format_char_info gcc_gfc_char_table
[] =
740 /* C89 conversion specifiers. */
741 { "di", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "", NULL
},
742 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "", NULL
},
743 { "c", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "", NULL
},
744 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
},
746 /* gfc conversion specifiers. */
748 { "C", 0, STD_C89
, NOARGUMENTS
, "", "", NULL
},
750 /* This will require a "locus" at runtime. */
751 { "L", 0, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "R", NULL
},
753 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
756 static const format_char_info scan_char_table
[] =
758 /* C89 conversion specifiers. */
759 { "di", 1, STD_C89
, { T89_I
, T99_SC
, T89_S
, T89_L
, T9L_LL
, TEX_LL
, T99_SST
, T99_PD
, T99_IM
, BADLEN
, BADLEN
, BADLEN
}, "*w'I", "W", NULL
},
760 { "u", 1, STD_C89
, { T89_UI
, T99_UC
, T89_US
, T89_UL
, T9L_ULL
, TEX_ULL
, T99_ST
, T99_UPD
, T99_UIM
, BADLEN
, BADLEN
, BADLEN
}, "*w'I", "W", NULL
},
761 { "oxX", 1, STD_C89
, { T89_UI
, T99_UC
, T89_US
, T89_UL
, T9L_ULL
, TEX_ULL
, T99_ST
, T99_UPD
, T99_UIM
, BADLEN
, BADLEN
, BADLEN
}, "*w", "W", NULL
},
762 { "efgEG", 1, STD_C89
, { T89_F
, BADLEN
, BADLEN
, T89_D
, BADLEN
, T89_LD
, BADLEN
, BADLEN
, BADLEN
, TEX_D32
, TEX_D64
, TEX_D128
}, "*w'", "W", NULL
},
763 { "c", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*mw", "cW", NULL
},
764 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*amw", "cW", NULL
},
765 { "[", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*amw", "cW[", NULL
},
766 { "p", 2, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w", "W", NULL
},
767 { "n", 1, STD_C89
, { T89_I
, T99_SC
, T89_S
, T89_L
, T9L_LL
, BADLEN
, T99_SST
, T99_PD
, T99_IM
, BADLEN
, BADLEN
, BADLEN
}, "", "W", NULL
},
768 /* C99 conversion specifiers. */
769 { "F", 1, STD_C99
, { T99_F
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T99_LD
, BADLEN
, BADLEN
, BADLEN
, TEX_D32
, TEX_D64
, TEX_D128
}, "*w'", "W", NULL
},
770 { "aA", 1, STD_C99
, { T99_F
, BADLEN
, BADLEN
, T99_D
, BADLEN
, T99_LD
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w'", "W", NULL
},
771 /* X/Open conversion specifiers. */
772 { "C", 1, STD_EXT
, { TEX_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*mw", "W", NULL
},
773 { "S", 1, STD_EXT
, { TEX_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*amw", "W", NULL
},
774 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
777 static const format_char_info time_char_table
[] =
779 /* C89 conversion specifiers. */
780 { "ABZab", 0, STD_C89
, NOLENGTHS
, "^#", "", NULL
},
781 { "cx", 0, STD_C89
, NOLENGTHS
, "E", "3", NULL
},
782 { "HIMSUWdmw", 0, STD_C89
, NOLENGTHS
, "-_0Ow", "", NULL
},
783 { "j", 0, STD_C89
, NOLENGTHS
, "-_0Ow", "o", NULL
},
784 { "p", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
785 { "X", 0, STD_C89
, NOLENGTHS
, "E", "", NULL
},
786 { "y", 0, STD_C89
, NOLENGTHS
, "EO-_0w", "4", NULL
},
787 { "Y", 0, STD_C89
, NOLENGTHS
, "-_0EOw", "o", NULL
},
788 { "%", 0, STD_C89
, NOLENGTHS
, "", "", NULL
},
789 /* C99 conversion specifiers. */
790 { "C", 0, STD_C99
, NOLENGTHS
, "-_0EOw", "o", NULL
},
791 { "D", 0, STD_C99
, NOLENGTHS
, "", "2", NULL
},
792 { "eVu", 0, STD_C99
, NOLENGTHS
, "-_0Ow", "", NULL
},
793 { "FRTnrt", 0, STD_C99
, NOLENGTHS
, "", "", NULL
},
794 { "g", 0, STD_C99
, NOLENGTHS
, "O-_0w", "2o", NULL
},
795 { "G", 0, STD_C99
, NOLENGTHS
, "-_0Ow", "o", NULL
},
796 { "h", 0, STD_C99
, NOLENGTHS
, "^#", "", NULL
},
797 { "z", 0, STD_C99
, NOLENGTHS
, "O", "o", NULL
},
798 /* GNU conversion specifiers. */
799 { "kls", 0, STD_EXT
, NOLENGTHS
, "-_0Ow", "", NULL
},
800 { "P", 0, STD_EXT
, NOLENGTHS
, "", "", NULL
},
801 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
804 static const format_char_info monetary_char_table
[] =
806 { "in", 0, STD_C89
, { T89_D
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, T89_LD
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "=^+(!-w#p", "", NULL
},
807 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
810 /* This must be in the same order as enum format_type. */
811 static const format_kind_info format_types_orig
[] =
813 { "gnu_printf", printf_length_specs
, print_char_table
, " +#0-'I", NULL
,
814 printf_flag_specs
, printf_flag_pairs
,
815 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_DOLLAR_MULTIPLE
|FMT_FLAG_USE_DOLLAR
|FMT_FLAG_EMPTY_PREC_OK
,
816 'w', 0, 'p', 0, 'L', 0,
817 &integer_type_node
, &integer_type_node
819 { "asm_fprintf", asm_fprintf_length_specs
, asm_fprintf_char_table
, " +#0-", NULL
,
820 asm_fprintf_flag_specs
, asm_fprintf_flag_pairs
,
821 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_EMPTY_PREC_OK
,
822 'w', 0, 'p', 0, 'L', 0,
825 { "gcc_diag", gcc_diag_length_specs
, gcc_diag_char_table
, "q+#", NULL
,
826 gcc_diag_flag_specs
, gcc_diag_flag_pairs
,
827 FMT_FLAG_ARG_CONVERT
,
828 0, 0, 'p', 0, 'L', 0,
829 NULL
, &integer_type_node
831 { "gcc_tdiag", gcc_tdiag_length_specs
, gcc_tdiag_char_table
, "q+#", NULL
,
832 gcc_tdiag_flag_specs
, gcc_tdiag_flag_pairs
,
833 FMT_FLAG_ARG_CONVERT
,
834 0, 0, 'p', 0, 'L', 0,
835 NULL
, &integer_type_node
837 { "gcc_cdiag", gcc_cdiag_length_specs
, gcc_cdiag_char_table
, "q+#", NULL
,
838 gcc_cdiag_flag_specs
, gcc_cdiag_flag_pairs
,
839 FMT_FLAG_ARG_CONVERT
,
840 0, 0, 'p', 0, 'L', 0,
841 NULL
, &integer_type_node
843 { "gcc_cxxdiag", gcc_cxxdiag_length_specs
, gcc_cxxdiag_char_table
, "q+#", NULL
,
844 gcc_cxxdiag_flag_specs
, gcc_cxxdiag_flag_pairs
,
845 FMT_FLAG_ARG_CONVERT
,
846 0, 0, 'p', 0, 'L', 0,
847 NULL
, &integer_type_node
849 { "gcc_gfc", gcc_gfc_length_specs
, gcc_gfc_char_table
, "", NULL
,
850 NULL
, gcc_gfc_flag_pairs
,
851 FMT_FLAG_ARG_CONVERT
,
855 { "NSString", NULL
, NULL
, NULL
, NULL
,
857 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL
, 0, 0, 0, 0, 0, 0,
860 { "gnu_scanf", scanf_length_specs
, scan_char_table
, "*'I", NULL
,
861 scanf_flag_specs
, scanf_flag_pairs
,
862 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_SCANF_A_KLUDGE
|FMT_FLAG_USE_DOLLAR
|FMT_FLAG_ZERO_WIDTH_BAD
|FMT_FLAG_DOLLAR_GAP_POINTER_OK
,
863 'w', 0, 0, '*', 'L', 'm',
866 { "gnu_strftime", NULL
, time_char_table
, "_-0^#", "EO",
867 strftime_flag_specs
, strftime_flag_pairs
,
868 FMT_FLAG_FANCY_PERCENT_OK
, 'w', 0, 0, 0, 0, 0,
871 { "gnu_strfmon", strfmon_length_specs
, monetary_char_table
, "=^+(!-", NULL
,
872 strfmon_flag_specs
, strfmon_flag_pairs
,
873 FMT_FLAG_ARG_CONVERT
, 'w', '#', 'p', 0, 'L', 0,
878 /* This layer of indirection allows GCC to reassign format_types with
879 new data if necessary, while still allowing the original data to be
881 static const format_kind_info
*format_types
= format_types_orig
;
882 /* We can modify this one. We also add target-specific format types
883 to the end of the array. */
884 static format_kind_info
*dynamic_format_types
;
886 static int n_format_types
= ARRAY_SIZE (format_types_orig
);
888 /* Structure detailing the results of checking a format function call
889 where the format expression may be a conditional expression with
890 many leaves resulting from nested conditional expressions. */
893 /* Number of leaves of the format argument that could not be checked
894 as they were not string literals. */
895 int number_non_literal
;
896 /* Number of leaves of the format argument that were null pointers or
897 string literals, but had extra format arguments. */
898 int number_extra_args
;
899 /* Number of leaves of the format argument that were null pointers or
900 string literals, but had extra format arguments and used $ operand
902 int number_dollar_extra_args
;
903 /* Number of leaves of the format argument that were wide string
906 /* Number of leaves of the format argument that were empty strings. */
908 /* Number of leaves of the format argument that were unterminated
910 int number_unterminated
;
911 /* Number of leaves of the format argument that were not counted above. */
913 } format_check_results
;
917 format_check_results
*res
;
918 function_format_info
*info
;
920 } format_check_context
;
922 /* Return the format name (as specified in the original table) for the format
923 type indicated by format_num. */
925 format_name (int format_num
)
927 if (format_num
>= 0 && format_num
< n_format_types
)
928 return format_types
[format_num
].name
;
932 /* Return the format flags (as specified in the original table) for the format
933 type indicated by format_num. */
935 format_flags (int format_num
)
937 if (format_num
>= 0 && format_num
< n_format_types
)
938 return format_types
[format_num
].flags
;
942 static void check_format_info (function_format_info
*, tree
);
943 static void check_format_arg (void *, tree
, unsigned HOST_WIDE_INT
);
944 static void check_format_info_main (format_check_results
*,
945 function_format_info
*,
946 const char *, int, tree
,
947 unsigned HOST_WIDE_INT
, alloc_pool
);
949 static void init_dollar_format_checking (int, tree
);
950 static int maybe_read_dollar_number (const char **, int,
951 tree
, tree
*, const format_kind_info
*);
952 static bool avoid_dollar_number (const char *);
953 static void finish_dollar_format_checking (format_check_results
*, int);
955 static const format_flag_spec
*get_flag_spec (const format_flag_spec
*,
958 static void check_format_types (format_wanted_type
*);
959 static void format_type_warning (format_wanted_type
*, tree
, tree
);
961 /* Decode a format type from a string, returning the type, or
962 format_type_error if not valid, in which case the caller should print an
965 decode_format_type (const char *s
)
970 s
= convert_format_name_to_system_name (s
);
972 for (i
= 0; i
< n_format_types
; i
++)
975 if (!strcmp (s
, format_types
[i
].name
))
977 alen
= strlen (format_types
[i
].name
);
978 if (slen
== alen
+ 4 && s
[0] == '_' && s
[1] == '_'
979 && s
[slen
- 1] == '_' && s
[slen
- 2] == '_'
980 && !strncmp (s
+ 2, format_types
[i
].name
, alen
))
983 return format_type_error
;
987 /* Check the argument list of a call to printf, scanf, etc.
988 ATTRS are the attributes on the function type. There are NARGS argument
989 values in the array ARGARRAY.
990 Also, if -Wsuggest-attribute=format,
991 warn for calls to vprintf or vscanf in functions with no such format
992 attribute themselves. */
995 check_function_format (tree attrs
, int nargs
, tree
*argarray
)
999 /* See if this function has any format attributes. */
1000 for (a
= attrs
; a
; a
= TREE_CHAIN (a
))
1002 if (is_attribute_p ("format", TREE_PURPOSE (a
)))
1004 /* Yup; check it. */
1005 function_format_info info
;
1006 decode_format_attr (TREE_VALUE (a
), &info
, 1);
1009 /* FIXME: Rewrite all the internal functions in this file
1010 to use the ARGARRAY directly instead of constructing this
1012 tree params
= NULL_TREE
;
1014 for (i
= nargs
- 1; i
>= 0; i
--)
1015 params
= tree_cons (NULL_TREE
, argarray
[i
], params
);
1016 check_format_info (&info
, params
);
1018 if (warn_suggest_attribute_format
&& info
.first_arg_num
== 0
1019 && (format_types
[info
.format_type
].flags
1020 & (int) FMT_FLAG_ARG_CONVERT
))
1023 for (c
= TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
));
1026 if (is_attribute_p ("format", TREE_PURPOSE (c
))
1027 && (decode_format_type (IDENTIFIER_POINTER
1028 (TREE_VALUE (TREE_VALUE (c
))))
1029 == info
.format_type
))
1033 /* Check if the current function has a parameter to which
1034 the format attribute could be attached; if not, it
1035 can't be a candidate for a format attribute, despite
1036 the vprintf-like or vscanf-like call. */
1038 for (args
= DECL_ARGUMENTS (current_function_decl
);
1040 args
= DECL_CHAIN (args
))
1042 if (TREE_CODE (TREE_TYPE (args
)) == POINTER_TYPE
1043 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (args
)))
1048 warning (OPT_Wsuggest_attribute_format
, "function might "
1049 "be possible candidate for %qs format attribute",
1050 format_types
[info
.format_type
].name
);
1058 /* Variables used by the checking of $ operand number formats. */
1059 static char *dollar_arguments_used
= NULL
;
1060 static char *dollar_arguments_pointer_p
= NULL
;
1061 static int dollar_arguments_alloc
= 0;
1062 static int dollar_arguments_count
;
1063 static int dollar_first_arg_num
;
1064 static int dollar_max_arg_used
;
1065 static int dollar_format_warned
;
1067 /* Initialize the checking for a format string that may contain $
1068 parameter number specifications; we will need to keep track of whether
1069 each parameter has been used. FIRST_ARG_NUM is the number of the first
1070 argument that is a parameter to the format, or 0 for a vprintf-style
1071 function; PARAMS is the list of arguments starting at this argument. */
1074 init_dollar_format_checking (int first_arg_num
, tree params
)
1076 tree oparams
= params
;
1078 dollar_first_arg_num
= first_arg_num
;
1079 dollar_arguments_count
= 0;
1080 dollar_max_arg_used
= 0;
1081 dollar_format_warned
= 0;
1082 if (first_arg_num
> 0)
1086 dollar_arguments_count
++;
1087 params
= TREE_CHAIN (params
);
1090 if (dollar_arguments_alloc
< dollar_arguments_count
)
1092 free (dollar_arguments_used
);
1093 free (dollar_arguments_pointer_p
);
1094 dollar_arguments_alloc
= dollar_arguments_count
;
1095 dollar_arguments_used
= XNEWVEC (char, dollar_arguments_alloc
);
1096 dollar_arguments_pointer_p
= XNEWVEC (char, dollar_arguments_alloc
);
1098 if (dollar_arguments_alloc
)
1100 memset (dollar_arguments_used
, 0, dollar_arguments_alloc
);
1101 if (first_arg_num
> 0)
1107 dollar_arguments_pointer_p
[i
] = (TREE_CODE (TREE_TYPE (TREE_VALUE (params
)))
1109 params
= TREE_CHAIN (params
);
1117 /* Look for a decimal number followed by a $ in *FORMAT. If DOLLAR_NEEDED
1118 is set, it is an error if one is not found; otherwise, it is OK. If
1119 such a number is found, check whether it is within range and mark that
1120 numbered operand as being used for later checking. Returns the operand
1121 number if found and within range, zero if no such number was found and
1122 this is OK, or -1 on error. PARAMS points to the first operand of the
1123 format; PARAM_PTR is made to point to the parameter referred to. If
1124 a $ format is found, *FORMAT is updated to point just after it. */
1127 maybe_read_dollar_number (const char **format
,
1128 int dollar_needed
, tree params
, tree
*param_ptr
,
1129 const format_kind_info
*fki
)
1133 const char *fcp
= *format
;
1134 if (!ISDIGIT (*fcp
))
1138 warning (OPT_Wformat_
, "missing $ operand number in format");
1146 while (ISDIGIT (*fcp
))
1149 nargnum
= 10 * argnum
+ (*fcp
- '0');
1150 if (nargnum
< 0 || nargnum
/ 10 != argnum
)
1159 warning (OPT_Wformat_
, "missing $ operand number in format");
1166 if (pedantic
&& !dollar_format_warned
)
1168 warning (OPT_Wformat_
, "%s does not support %%n$ operand number formats",
1169 C_STD_NAME (STD_EXT
));
1170 dollar_format_warned
= 1;
1172 if (overflow_flag
|| argnum
== 0
1173 || (dollar_first_arg_num
&& argnum
> dollar_arguments_count
))
1175 warning (OPT_Wformat_
, "operand number out of range in format");
1178 if (argnum
> dollar_max_arg_used
)
1179 dollar_max_arg_used
= argnum
;
1180 /* For vprintf-style functions we may need to allocate more memory to
1181 track which arguments are used. */
1182 while (dollar_arguments_alloc
< dollar_max_arg_used
)
1185 nalloc
= 2 * dollar_arguments_alloc
+ 16;
1186 dollar_arguments_used
= XRESIZEVEC (char, dollar_arguments_used
,
1188 dollar_arguments_pointer_p
= XRESIZEVEC (char, dollar_arguments_pointer_p
,
1190 memset (dollar_arguments_used
+ dollar_arguments_alloc
, 0,
1191 nalloc
- dollar_arguments_alloc
);
1192 dollar_arguments_alloc
= nalloc
;
1194 if (!(fki
->flags
& (int) FMT_FLAG_DOLLAR_MULTIPLE
)
1195 && dollar_arguments_used
[argnum
- 1] == 1)
1197 dollar_arguments_used
[argnum
- 1] = 2;
1198 warning (OPT_Wformat_
, "format argument %d used more than once in %s format",
1202 dollar_arguments_used
[argnum
- 1] = 1;
1203 if (dollar_first_arg_num
)
1206 *param_ptr
= params
;
1207 for (i
= 1; i
< argnum
&& *param_ptr
!= 0; i
++)
1208 *param_ptr
= TREE_CHAIN (*param_ptr
);
1210 /* This case shouldn't be caught here. */
1211 gcc_assert (*param_ptr
);
1218 /* Ensure that FORMAT does not start with a decimal number followed by
1219 a $; give a diagnostic and return true if it does, false otherwise. */
1222 avoid_dollar_number (const char *format
)
1224 if (!ISDIGIT (*format
))
1226 while (ISDIGIT (*format
))
1230 warning (OPT_Wformat_
, "$ operand number used after format without operand number");
1237 /* Finish the checking for a format string that used $ operand number formats
1238 instead of non-$ formats. We check for unused operands before used ones
1239 (a serious error, since the implementation of the format function
1240 can't know what types to pass to va_arg to find the later arguments).
1241 and for unused operands at the end of the format (if we know how many
1242 arguments the format had, so not for vprintf). If there were operand
1243 numbers out of range on a non-vprintf-style format, we won't have reached
1244 here. If POINTER_GAP_OK, unused arguments are OK if all arguments are
1248 finish_dollar_format_checking (format_check_results
*res
, int pointer_gap_ok
)
1251 bool found_pointer_gap
= false;
1252 for (i
= 0; i
< dollar_max_arg_used
; i
++)
1254 if (!dollar_arguments_used
[i
])
1256 if (pointer_gap_ok
&& (dollar_first_arg_num
== 0
1257 || dollar_arguments_pointer_p
[i
]))
1258 found_pointer_gap
= true;
1260 warning (OPT_Wformat_
,
1261 "format argument %d unused before used argument %d in $-style format",
1262 i
+ 1, dollar_max_arg_used
);
1265 if (found_pointer_gap
1266 || (dollar_first_arg_num
1267 && dollar_max_arg_used
< dollar_arguments_count
))
1269 res
->number_other
--;
1270 res
->number_dollar_extra_args
++;
1275 /* Retrieve the specification for a format flag. SPEC contains the
1276 specifications for format flags for the applicable kind of format.
1277 FLAG is the flag in question. If PREDICATES is NULL, the basic
1278 spec for that flag must be retrieved and must exist. If
1279 PREDICATES is not NULL, it is a string listing possible predicates
1280 for the spec entry; if an entry predicated on any of these is
1281 found, it is returned, otherwise NULL is returned. */
1283 static const format_flag_spec
*
1284 get_flag_spec (const format_flag_spec
*spec
, int flag
, const char *predicates
)
1287 for (i
= 0; spec
[i
].flag_char
!= 0; i
++)
1289 if (spec
[i
].flag_char
!= flag
)
1291 if (predicates
!= NULL
)
1293 if (spec
[i
].predicate
!= 0
1294 && strchr (predicates
, spec
[i
].predicate
) != 0)
1297 else if (spec
[i
].predicate
== 0)
1300 gcc_assert (predicates
);
1305 /* Check the argument list of a call to printf, scanf, etc.
1306 INFO points to the function_format_info structure.
1307 PARAMS is the list of argument values. */
1310 check_format_info (function_format_info
*info
, tree params
)
1312 format_check_context format_ctx
;
1313 unsigned HOST_WIDE_INT arg_num
;
1315 format_check_results res
;
1316 /* Skip to format argument. If the argument isn't available, there's
1317 no work for us to do; prototype checking will catch the problem. */
1318 for (arg_num
= 1; ; ++arg_num
)
1322 if (arg_num
== info
->format_num
)
1324 params
= TREE_CHAIN (params
);
1326 format_tree
= TREE_VALUE (params
);
1327 params
= TREE_CHAIN (params
);
1328 if (format_tree
== 0)
1331 res
.number_non_literal
= 0;
1332 res
.number_extra_args
= 0;
1333 res
.number_dollar_extra_args
= 0;
1334 res
.number_wide
= 0;
1335 res
.number_empty
= 0;
1336 res
.number_unterminated
= 0;
1337 res
.number_other
= 0;
1339 format_ctx
.res
= &res
;
1340 format_ctx
.info
= info
;
1341 format_ctx
.params
= params
;
1343 check_function_arguments_recurse (check_format_arg
, &format_ctx
,
1344 format_tree
, arg_num
);
1346 if (res
.number_non_literal
> 0)
1348 /* Functions taking a va_list normally pass a non-literal format
1349 string. These functions typically are declared with
1350 first_arg_num == 0, so avoid warning in those cases. */
1351 if (!(format_types
[info
->format_type
].flags
& (int) FMT_FLAG_ARG_CONVERT
))
1353 /* For strftime-like formats, warn for not checking the format
1354 string; but there are no arguments to check. */
1355 warning (OPT_Wformat_nonliteral
,
1356 "format not a string literal, format string not checked");
1358 else if (info
->first_arg_num
!= 0)
1360 /* If there are no arguments for the format at all, we may have
1361 printf (foo) which is likely to be a security hole. */
1362 while (arg_num
+ 1 < info
->first_arg_num
)
1366 params
= TREE_CHAIN (params
);
1369 if (params
== 0 && warn_format_security
)
1370 warning (OPT_Wformat_security
,
1371 "format not a string literal and no format arguments");
1372 else if (params
== 0 && warn_format_nonliteral
)
1373 warning (OPT_Wformat_nonliteral
,
1374 "format not a string literal and no format arguments");
1376 warning (OPT_Wformat_nonliteral
,
1377 "format not a string literal, argument types not checked");
1381 /* If there were extra arguments to the format, normally warn. However,
1382 the standard does say extra arguments are ignored, so in the specific
1383 case where we have multiple leaves (conditional expressions or
1384 ngettext) allow extra arguments if at least one leaf didn't have extra
1385 arguments, but was otherwise OK (either non-literal or checked OK).
1386 If the format is an empty string, this should be counted similarly to the
1387 case of extra format arguments. */
1388 if (res
.number_extra_args
> 0 && res
.number_non_literal
== 0
1389 && res
.number_other
== 0)
1390 warning (OPT_Wformat_extra_args
, "too many arguments for format");
1391 if (res
.number_dollar_extra_args
> 0 && res
.number_non_literal
== 0
1392 && res
.number_other
== 0)
1393 warning (OPT_Wformat_extra_args
, "unused arguments in $-style format");
1394 if (res
.number_empty
> 0 && res
.number_non_literal
== 0
1395 && res
.number_other
== 0)
1396 warning (OPT_Wformat_zero_length
, "zero-length %s format string",
1397 format_types
[info
->format_type
].name
);
1399 if (res
.number_wide
> 0)
1400 warning (OPT_Wformat_
, "format is a wide character string");
1402 if (res
.number_unterminated
> 0)
1403 warning (OPT_Wformat_
, "unterminated format string");
1406 /* Callback from check_function_arguments_recurse to check a
1407 format string. FORMAT_TREE is the format parameter. ARG_NUM
1408 is the number of the format argument. CTX points to a
1409 format_check_context. */
1412 check_format_arg (void *ctx
, tree format_tree
,
1413 unsigned HOST_WIDE_INT arg_num
)
1415 format_check_context
*format_ctx
= (format_check_context
*) ctx
;
1416 format_check_results
*res
= format_ctx
->res
;
1417 function_format_info
*info
= format_ctx
->info
;
1418 tree params
= format_ctx
->params
;
1421 HOST_WIDE_INT offset
;
1422 const char *format_chars
;
1423 tree array_size
= 0;
1425 alloc_pool fwt_pool
;
1427 if (integer_zerop (format_tree
))
1429 /* Skip to first argument to check, so we can see if this format
1430 has any arguments (it shouldn't). */
1431 while (arg_num
+ 1 < info
->first_arg_num
)
1435 params
= TREE_CHAIN (params
);
1440 res
->number_other
++;
1442 res
->number_extra_args
++;
1448 if (TREE_CODE (format_tree
) == POINTER_PLUS_EXPR
)
1452 arg0
= TREE_OPERAND (format_tree
, 0);
1453 arg1
= TREE_OPERAND (format_tree
, 1);
1456 if (TREE_CODE (arg1
) == INTEGER_CST
)
1460 res
->number_non_literal
++;
1463 if (!tree_fits_shwi_p (arg1
)
1464 || (offset
= tree_to_shwi (arg1
)) < 0)
1466 res
->number_non_literal
++;
1470 if (TREE_CODE (format_tree
) != ADDR_EXPR
)
1472 res
->number_non_literal
++;
1475 format_tree
= TREE_OPERAND (format_tree
, 0);
1476 if (format_types
[info
->format_type
].flags
1477 & (int) FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL
)
1479 bool objc_str
= (info
->format_type
== gcc_objc_string_format_type
);
1480 /* We cannot examine this string here - but we can check that it is
1482 if (TREE_CODE (format_tree
) != CONST_DECL
1483 || !((objc_str
&& objc_string_ref_type_p (TREE_TYPE (format_tree
)))
1484 || (*targetcm
.string_object_ref_type_p
)
1485 ((const_tree
) TREE_TYPE (format_tree
))))
1487 res
->number_non_literal
++;
1490 /* Skip to first argument to check. */
1491 while (arg_num
+ 1 < info
->first_arg_num
)
1495 params
= TREE_CHAIN (params
);
1498 /* So, we have a valid literal string object and one or more params.
1499 We need to use an external helper to parse the string into format
1500 info. For Objective-C variants we provide the resource within the
1501 objc tree, for target variants, via a hook. */
1503 objc_check_format_arg (format_tree
, params
);
1504 else if (targetcm
.check_string_object_format_arg
)
1505 (*targetcm
.check_string_object_format_arg
) (format_tree
, params
);
1506 /* Else we can't handle it and retire quietly. */
1509 if (TREE_CODE (format_tree
) == ARRAY_REF
1510 && tree_fits_shwi_p (TREE_OPERAND (format_tree
, 1))
1511 && (offset
+= tree_to_shwi (TREE_OPERAND (format_tree
, 1))) >= 0)
1512 format_tree
= TREE_OPERAND (format_tree
, 0);
1513 if (TREE_CODE (format_tree
) == VAR_DECL
1514 && TREE_CODE (TREE_TYPE (format_tree
)) == ARRAY_TYPE
1515 && (array_init
= decl_constant_value (format_tree
)) != format_tree
1516 && TREE_CODE (array_init
) == STRING_CST
)
1518 /* Extract the string constant initializer. Note that this may include
1519 a trailing NUL character that is not in the array (e.g.
1520 const char a[3] = "foo";). */
1521 array_size
= DECL_SIZE_UNIT (format_tree
);
1522 format_tree
= array_init
;
1524 if (TREE_CODE (format_tree
) != STRING_CST
)
1526 res
->number_non_literal
++;
1529 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (format_tree
))) != char_type_node
)
1534 format_chars
= TREE_STRING_POINTER (format_tree
);
1535 format_length
= TREE_STRING_LENGTH (format_tree
);
1536 if (array_size
!= 0)
1538 /* Variable length arrays can't be initialized. */
1539 gcc_assert (TREE_CODE (array_size
) == INTEGER_CST
);
1541 if (tree_fits_shwi_p (array_size
))
1543 HOST_WIDE_INT array_size_value
= tree_to_shwi (array_size
);
1544 if (array_size_value
> 0
1545 && array_size_value
== (int) array_size_value
1546 && format_length
> array_size_value
)
1547 format_length
= array_size_value
;
1552 if (offset
>= format_length
)
1554 res
->number_non_literal
++;
1557 format_chars
+= offset
;
1558 format_length
-= offset
;
1560 if (format_length
< 1 || format_chars
[--format_length
] != 0)
1562 res
->number_unterminated
++;
1565 if (format_length
== 0)
1567 res
->number_empty
++;
1571 /* Skip to first argument to check. */
1572 while (arg_num
+ 1 < info
->first_arg_num
)
1576 params
= TREE_CHAIN (params
);
1579 /* Provisionally increment res->number_other; check_format_info_main
1580 will decrement it if it finds there are extra arguments, but this way
1581 need not adjust it for every return. */
1582 res
->number_other
++;
1583 fwt_pool
= create_alloc_pool ("format_wanted_type pool",
1584 sizeof (format_wanted_type
), 10);
1585 check_format_info_main (res
, info
, format_chars
, format_length
,
1586 params
, arg_num
, fwt_pool
);
1587 free_alloc_pool (fwt_pool
);
1591 /* Do the main part of checking a call to a format function. FORMAT_CHARS
1592 is the NUL-terminated format string (which at this point may contain
1593 internal NUL characters); FORMAT_LENGTH is its length (excluding the
1594 terminating NUL character). ARG_NUM is one less than the number of
1595 the first format argument to check; PARAMS points to that format
1596 argument in the list of arguments. */
1599 check_format_info_main (format_check_results
*res
,
1600 function_format_info
*info
, const char *format_chars
,
1601 int format_length
, tree params
,
1602 unsigned HOST_WIDE_INT arg_num
, alloc_pool fwt_pool
)
1604 const char *orig_format_chars
= format_chars
;
1605 tree first_fillin_param
= params
;
1607 const format_kind_info
*fki
= &format_types
[info
->format_type
];
1608 const format_flag_spec
*flag_specs
= fki
->flag_specs
;
1609 const format_flag_pair
*bad_flag_pairs
= fki
->bad_flag_pairs
;
1611 /* -1 if no conversions taking an operand have been found; 0 if one has
1612 and it didn't use $; 1 if $ formats are in use. */
1613 int has_operand_number
= -1;
1615 init_dollar_format_checking (info
->first_arg_num
, first_fillin_param
);
1617 while (*format_chars
!= 0)
1620 int suppressed
= FALSE
;
1621 const char *length_chars
= NULL
;
1622 enum format_lengths length_chars_val
= FMT_LEN_none
;
1623 enum format_std_version length_chars_std
= STD_C89
;
1627 int main_arg_num
= 0;
1628 tree main_arg_params
= 0;
1629 enum format_std_version wanted_type_std
;
1630 const char *wanted_type_name
;
1631 format_wanted_type width_wanted_type
;
1632 format_wanted_type precision_wanted_type
;
1633 format_wanted_type main_wanted_type
;
1634 format_wanted_type
*first_wanted_type
= NULL
;
1635 format_wanted_type
*last_wanted_type
= NULL
;
1636 const format_length_info
*fli
= NULL
;
1637 const format_char_info
*fci
= NULL
;
1638 char flag_chars
[256];
1640 int scalar_identity_flag
= 0;
1641 const char *format_start
;
1643 if (*format_chars
++ != '%')
1645 if (*format_chars
== 0)
1647 warning (OPT_Wformat_
, "spurious trailing %<%%%> in format");
1650 if (*format_chars
== '%')
1657 if ((fki
->flags
& (int) FMT_FLAG_USE_DOLLAR
) && has_operand_number
!= 0)
1659 /* Possibly read a $ operand number at the start of the format.
1660 If one was previously used, one is required here. If one
1661 is not used here, we can't immediately conclude this is a
1662 format without them, since it could be printf %m or scanf %*. */
1664 opnum
= maybe_read_dollar_number (&format_chars
, 0,
1666 &main_arg_params
, fki
);
1671 has_operand_number
= 1;
1672 main_arg_num
= opnum
+ info
->first_arg_num
- 1;
1675 else if (fki
->flags
& FMT_FLAG_USE_DOLLAR
)
1677 if (avoid_dollar_number (format_chars
))
1681 /* Read any format flags, but do not yet validate them beyond removing
1682 duplicates, since in general validation depends on the rest of
1684 while (*format_chars
!= 0
1685 && strchr (fki
->flag_chars
, *format_chars
) != 0)
1687 const format_flag_spec
*s
= get_flag_spec (flag_specs
,
1688 *format_chars
, NULL
);
1689 if (strchr (flag_chars
, *format_chars
) != 0)
1691 warning (OPT_Wformat_
, "repeated %s in format", _(s
->name
));
1695 i
= strlen (flag_chars
);
1696 flag_chars
[i
++] = *format_chars
;
1699 if (s
->skip_next_char
)
1702 if (*format_chars
== 0)
1704 warning (OPT_Wformat_
, "missing fill character at end of strfmon format");
1711 /* Read any format width, possibly * or *m$. */
1712 if (fki
->width_char
!= 0)
1714 if (fki
->width_type
!= NULL
&& *format_chars
== '*')
1716 i
= strlen (flag_chars
);
1717 flag_chars
[i
++] = fki
->width_char
;
1719 /* "...a field width...may be indicated by an asterisk.
1720 In this case, an int argument supplies the field width..." */
1722 if (has_operand_number
!= 0)
1725 opnum
= maybe_read_dollar_number (&format_chars
,
1726 has_operand_number
== 1,
1733 has_operand_number
= 1;
1734 arg_num
= opnum
+ info
->first_arg_num
- 1;
1737 has_operand_number
= 0;
1741 if (avoid_dollar_number (format_chars
))
1744 if (info
->first_arg_num
!= 0)
1750 cur_param
= TREE_VALUE (params
);
1751 if (has_operand_number
<= 0)
1753 params
= TREE_CHAIN (params
);
1757 width_wanted_type
.wanted_type
= *fki
->width_type
;
1758 width_wanted_type
.wanted_type_name
= NULL
;
1759 width_wanted_type
.pointer_count
= 0;
1760 width_wanted_type
.char_lenient_flag
= 0;
1761 width_wanted_type
.scalar_identity_flag
= 0;
1762 width_wanted_type
.writing_in_flag
= 0;
1763 width_wanted_type
.reading_from_flag
= 0;
1764 width_wanted_type
.kind
= CF_KIND_FIELD_WIDTH
;
1765 width_wanted_type
.format_start
= format_chars
- 1;
1766 width_wanted_type
.format_length
= 1;
1767 width_wanted_type
.param
= cur_param
;
1768 width_wanted_type
.arg_num
= arg_num
;
1769 width_wanted_type
.next
= NULL
;
1770 if (last_wanted_type
!= 0)
1771 last_wanted_type
->next
= &width_wanted_type
;
1772 if (first_wanted_type
== 0)
1773 first_wanted_type
= &width_wanted_type
;
1774 last_wanted_type
= &width_wanted_type
;
1779 /* Possibly read a numeric width. If the width is zero,
1780 we complain if appropriate. */
1781 int non_zero_width_char
= FALSE
;
1782 int found_width
= FALSE
;
1783 while (ISDIGIT (*format_chars
))
1786 if (*format_chars
!= '0')
1787 non_zero_width_char
= TRUE
;
1790 if (found_width
&& !non_zero_width_char
&&
1791 (fki
->flags
& (int) FMT_FLAG_ZERO_WIDTH_BAD
))
1792 warning (OPT_Wformat_
, "zero width in %s format", fki
->name
);
1795 i
= strlen (flag_chars
);
1796 flag_chars
[i
++] = fki
->width_char
;
1802 /* Read any format left precision (must be a number, not *). */
1803 if (fki
->left_precision_char
!= 0 && *format_chars
== '#')
1806 i
= strlen (flag_chars
);
1807 flag_chars
[i
++] = fki
->left_precision_char
;
1809 if (!ISDIGIT (*format_chars
))
1810 warning (OPT_Wformat_
, "empty left precision in %s format", fki
->name
);
1811 while (ISDIGIT (*format_chars
))
1815 /* Read any format precision, possibly * or *m$. */
1816 if (fki
->precision_char
!= 0 && *format_chars
== '.')
1819 i
= strlen (flag_chars
);
1820 flag_chars
[i
++] = fki
->precision_char
;
1822 if (fki
->precision_type
!= NULL
&& *format_chars
== '*')
1824 /* "...a...precision...may be indicated by an asterisk.
1825 In this case, an int argument supplies the...precision." */
1827 if (has_operand_number
!= 0)
1830 opnum
= maybe_read_dollar_number (&format_chars
,
1831 has_operand_number
== 1,
1838 has_operand_number
= 1;
1839 arg_num
= opnum
+ info
->first_arg_num
- 1;
1842 has_operand_number
= 0;
1846 if (avoid_dollar_number (format_chars
))
1849 if (info
->first_arg_num
!= 0)
1855 cur_param
= TREE_VALUE (params
);
1856 if (has_operand_number
<= 0)
1858 params
= TREE_CHAIN (params
);
1862 precision_wanted_type
.wanted_type
= *fki
->precision_type
;
1863 precision_wanted_type
.wanted_type_name
= NULL
;
1864 precision_wanted_type
.pointer_count
= 0;
1865 precision_wanted_type
.char_lenient_flag
= 0;
1866 precision_wanted_type
.scalar_identity_flag
= 0;
1867 precision_wanted_type
.writing_in_flag
= 0;
1868 precision_wanted_type
.reading_from_flag
= 0;
1869 precision_wanted_type
.kind
= CF_KIND_FIELD_PRECISION
;
1870 precision_wanted_type
.param
= cur_param
;
1871 precision_wanted_type
.format_start
= format_chars
- 2;
1872 precision_wanted_type
.format_length
= 2;
1873 precision_wanted_type
.arg_num
= arg_num
;
1874 precision_wanted_type
.next
= NULL
;
1875 if (last_wanted_type
!= 0)
1876 last_wanted_type
->next
= &precision_wanted_type
;
1877 if (first_wanted_type
== 0)
1878 first_wanted_type
= &precision_wanted_type
;
1879 last_wanted_type
= &precision_wanted_type
;
1884 if (!(fki
->flags
& (int) FMT_FLAG_EMPTY_PREC_OK
)
1885 && !ISDIGIT (*format_chars
))
1886 warning (OPT_Wformat_
, "empty precision in %s format", fki
->name
);
1887 while (ISDIGIT (*format_chars
))
1892 format_start
= format_chars
;
1893 if (fki
->alloc_char
&& fki
->alloc_char
== *format_chars
)
1895 i
= strlen (flag_chars
);
1896 flag_chars
[i
++] = fki
->alloc_char
;
1901 /* Handle the scanf allocation kludge. */
1902 if (fki
->flags
& (int) FMT_FLAG_SCANF_A_KLUDGE
)
1904 if (*format_chars
== 'a' && !flag_isoc99
)
1906 if (format_chars
[1] == 's' || format_chars
[1] == 'S'
1907 || format_chars
[1] == '[')
1909 /* 'a' is used as a flag. */
1910 i
= strlen (flag_chars
);
1911 flag_chars
[i
++] = 'a';
1918 /* Read any length modifier, if this kind of format has them. */
1919 fli
= fki
->length_char_specs
;
1920 length_chars
= NULL
;
1921 length_chars_val
= FMT_LEN_none
;
1922 length_chars_std
= STD_C89
;
1923 scalar_identity_flag
= 0;
1926 while (fli
->name
!= 0
1927 && strncmp (fli
->name
, format_chars
, strlen (fli
->name
)))
1931 format_chars
+= strlen (fli
->name
);
1932 if (fli
->double_name
!= 0 && fli
->name
[0] == *format_chars
)
1935 length_chars
= fli
->double_name
;
1936 length_chars_val
= fli
->double_index
;
1937 length_chars_std
= fli
->double_std
;
1941 length_chars
= fli
->name
;
1942 length_chars_val
= fli
->index
;
1943 length_chars_std
= fli
->std
;
1944 scalar_identity_flag
= fli
->scalar_identity_flag
;
1946 i
= strlen (flag_chars
);
1947 flag_chars
[i
++] = fki
->length_code_char
;
1952 /* Warn if the length modifier is non-standard. */
1953 if (ADJ_STD (length_chars_std
) > C_STD_VER
)
1954 warning (OPT_Wformat_
,
1955 "%s does not support the %qs %s length modifier",
1956 C_STD_NAME (length_chars_std
), length_chars
,
1961 /* Read any modifier (strftime E/O). */
1962 if (fki
->modifier_chars
!= NULL
)
1964 while (*format_chars
!= 0
1965 && strchr (fki
->modifier_chars
, *format_chars
) != 0)
1967 if (strchr (flag_chars
, *format_chars
) != 0)
1969 const format_flag_spec
*s
= get_flag_spec (flag_specs
,
1970 *format_chars
, NULL
);
1971 warning (OPT_Wformat_
, "repeated %s in format", _(s
->name
));
1975 i
= strlen (flag_chars
);
1976 flag_chars
[i
++] = *format_chars
;
1983 format_char
= *format_chars
;
1984 if (format_char
== 0
1985 || (!(fki
->flags
& (int) FMT_FLAG_FANCY_PERCENT_OK
)
1986 && format_char
== '%'))
1988 warning (OPT_Wformat_
, "conversion lacks type at end of format");
1992 fci
= fki
->conversion_specs
;
1993 while (fci
->format_chars
!= 0
1994 && strchr (fci
->format_chars
, format_char
) == 0)
1996 if (fci
->format_chars
== 0)
1998 if (ISGRAPH (format_char
))
1999 warning (OPT_Wformat_
, "unknown conversion type character %qc in format",
2002 warning (OPT_Wformat_
, "unknown conversion type character 0x%x in format",
2008 if (ADJ_STD (fci
->std
) > C_STD_VER
)
2009 warning (OPT_Wformat_
, "%s does not support the %<%%%c%> %s format",
2010 C_STD_NAME (fci
->std
), format_char
, fki
->name
);
2013 /* Validate the individual flags used, removing any that are invalid. */
2016 for (i
= 0; flag_chars
[i
] != 0; i
++)
2018 const format_flag_spec
*s
= get_flag_spec (flag_specs
,
2019 flag_chars
[i
], NULL
);
2020 flag_chars
[i
- d
] = flag_chars
[i
];
2021 if (flag_chars
[i
] == fki
->length_code_char
)
2023 if (strchr (fci
->flag_chars
, flag_chars
[i
]) == 0)
2025 warning (OPT_Wformat_
, "%s used with %<%%%c%> %s format",
2026 _(s
->name
), format_char
, fki
->name
);
2032 const format_flag_spec
*t
;
2033 if (ADJ_STD (s
->std
) > C_STD_VER
)
2034 warning (OPT_Wformat_
, "%s does not support %s",
2035 C_STD_NAME (s
->std
), _(s
->long_name
));
2036 t
= get_flag_spec (flag_specs
, flag_chars
[i
], fci
->flags2
);
2037 if (t
!= NULL
&& ADJ_STD (t
->std
) > ADJ_STD (s
->std
))
2039 const char *long_name
= (t
->long_name
!= NULL
2042 if (ADJ_STD (t
->std
) > C_STD_VER
)
2043 warning (OPT_Wformat_
,
2044 "%s does not support %s with the %<%%%c%> %s format",
2045 C_STD_NAME (t
->std
), _(long_name
),
2046 format_char
, fki
->name
);
2050 flag_chars
[i
- d
] = 0;
2053 if ((fki
->flags
& (int) FMT_FLAG_SCANF_A_KLUDGE
)
2054 && strchr (flag_chars
, 'a') != 0)
2056 if (fki
->alloc_char
&& strchr (flag_chars
, fki
->alloc_char
) != 0)
2059 if (fki
->suppression_char
2060 && strchr (flag_chars
, fki
->suppression_char
) != 0)
2063 /* Validate the pairs of flags used. */
2064 for (i
= 0; bad_flag_pairs
[i
].flag_char1
!= 0; i
++)
2066 const format_flag_spec
*s
, *t
;
2067 if (strchr (flag_chars
, bad_flag_pairs
[i
].flag_char1
) == 0)
2069 if (strchr (flag_chars
, bad_flag_pairs
[i
].flag_char2
) == 0)
2071 if (bad_flag_pairs
[i
].predicate
!= 0
2072 && strchr (fci
->flags2
, bad_flag_pairs
[i
].predicate
) == 0)
2074 s
= get_flag_spec (flag_specs
, bad_flag_pairs
[i
].flag_char1
, NULL
);
2075 t
= get_flag_spec (flag_specs
, bad_flag_pairs
[i
].flag_char2
, NULL
);
2076 if (bad_flag_pairs
[i
].ignored
)
2078 if (bad_flag_pairs
[i
].predicate
!= 0)
2079 warning (OPT_Wformat_
,
2080 "%s ignored with %s and %<%%%c%> %s format",
2081 _(s
->name
), _(t
->name
), format_char
,
2084 warning (OPT_Wformat_
, "%s ignored with %s in %s format",
2085 _(s
->name
), _(t
->name
), fki
->name
);
2089 if (bad_flag_pairs
[i
].predicate
!= 0)
2090 warning (OPT_Wformat_
,
2091 "use of %s and %s together with %<%%%c%> %s format",
2092 _(s
->name
), _(t
->name
), format_char
,
2095 warning (OPT_Wformat_
, "use of %s and %s together in %s format",
2096 _(s
->name
), _(t
->name
), fki
->name
);
2100 /* Give Y2K warnings. */
2101 if (warn_format_y2k
)
2104 if (strchr (fci
->flags2
, '4') != 0)
2105 if (strchr (flag_chars
, 'E') != 0)
2109 else if (strchr (fci
->flags2
, '3') != 0)
2111 else if (strchr (fci
->flags2
, '2') != 0)
2114 warning (OPT_Wformat_y2k
, "%<%%%c%> yields only last 2 digits of "
2115 "year in some locales", format_char
);
2116 else if (y2k_level
== 2)
2117 warning (OPT_Wformat_y2k
, "%<%%%c%> yields only last 2 digits of "
2118 "year", format_char
);
2121 if (strchr (fci
->flags2
, '[') != 0)
2123 /* Skip over scan set, in case it happens to have '%' in it. */
2124 if (*format_chars
== '^')
2126 /* Find closing bracket; if one is hit immediately, then
2127 it's part of the scan set rather than a terminator. */
2128 if (*format_chars
== ']')
2130 while (*format_chars
&& *format_chars
!= ']')
2132 if (*format_chars
!= ']')
2133 /* The end of the format string was reached. */
2134 warning (OPT_Wformat_
, "no closing %<]%> for %<%%[%> format");
2138 wanted_type_name
= 0;
2139 if (fki
->flags
& (int) FMT_FLAG_ARG_CONVERT
)
2141 wanted_type
= (fci
->types
[length_chars_val
].type
2142 ? *fci
->types
[length_chars_val
].type
: 0);
2143 wanted_type_name
= fci
->types
[length_chars_val
].name
;
2144 wanted_type_std
= fci
->types
[length_chars_val
].std
;
2145 if (wanted_type
== 0)
2147 warning (OPT_Wformat_
,
2148 "use of %qs length modifier with %qc type character",
2149 length_chars
, format_char
);
2150 /* Heuristic: skip one argument when an invalid length/type
2151 combination is encountered. */
2154 params
= TREE_CHAIN (params
);
2158 /* Warn if non-standard, provided it is more non-standard
2159 than the length and type characters that may already
2160 have been warned for. */
2161 && ADJ_STD (wanted_type_std
) > ADJ_STD (length_chars_std
)
2162 && ADJ_STD (wanted_type_std
) > ADJ_STD (fci
->std
))
2164 if (ADJ_STD (wanted_type_std
) > C_STD_VER
)
2165 warning (OPT_Wformat_
,
2166 "%s does not support the %<%%%s%c%> %s format",
2167 C_STD_NAME (wanted_type_std
), length_chars
,
2168 format_char
, fki
->name
);
2172 main_wanted_type
.next
= NULL
;
2174 /* Finally. . .check type of argument against desired type! */
2175 if (info
->first_arg_num
== 0)
2177 if ((fci
->pointer_count
== 0 && wanted_type
== void_type_node
)
2180 if (main_arg_num
!= 0)
2183 warning (OPT_Wformat_
, "operand number specified with "
2184 "suppressed assignment");
2186 warning (OPT_Wformat_
, "operand number specified for format "
2187 "taking no argument");
2192 format_wanted_type
*wanted_type_ptr
;
2194 if (main_arg_num
!= 0)
2196 arg_num
= main_arg_num
;
2197 params
= main_arg_params
;
2202 if (has_operand_number
> 0)
2204 warning (OPT_Wformat_
, "missing $ operand number in format");
2208 has_operand_number
= 0;
2211 wanted_type_ptr
= &main_wanted_type
;
2218 cur_param
= TREE_VALUE (params
);
2219 params
= TREE_CHAIN (params
);
2222 wanted_type_ptr
->wanted_type
= wanted_type
;
2223 wanted_type_ptr
->wanted_type_name
= wanted_type_name
;
2224 wanted_type_ptr
->pointer_count
= fci
->pointer_count
+ alloc_flag
;
2225 wanted_type_ptr
->char_lenient_flag
= 0;
2226 if (strchr (fci
->flags2
, 'c') != 0)
2227 wanted_type_ptr
->char_lenient_flag
= 1;
2228 wanted_type_ptr
->scalar_identity_flag
= 0;
2229 if (scalar_identity_flag
)
2230 wanted_type_ptr
->scalar_identity_flag
= 1;
2231 wanted_type_ptr
->writing_in_flag
= 0;
2232 wanted_type_ptr
->reading_from_flag
= 0;
2234 wanted_type_ptr
->writing_in_flag
= 1;
2237 if (strchr (fci
->flags2
, 'W') != 0)
2238 wanted_type_ptr
->writing_in_flag
= 1;
2239 if (strchr (fci
->flags2
, 'R') != 0)
2240 wanted_type_ptr
->reading_from_flag
= 1;
2242 wanted_type_ptr
->kind
= CF_KIND_FORMAT
;
2243 wanted_type_ptr
->param
= cur_param
;
2244 wanted_type_ptr
->arg_num
= arg_num
;
2245 wanted_type_ptr
->format_start
= format_start
;
2246 wanted_type_ptr
->format_length
= format_chars
- format_start
;
2247 wanted_type_ptr
->next
= NULL
;
2248 if (last_wanted_type
!= 0)
2249 last_wanted_type
->next
= wanted_type_ptr
;
2250 if (first_wanted_type
== 0)
2251 first_wanted_type
= wanted_type_ptr
;
2252 last_wanted_type
= wanted_type_ptr
;
2257 wanted_type_ptr
= (format_wanted_type
*)
2258 pool_alloc (fwt_pool
);
2260 wanted_type
= *fci
->types
[length_chars_val
].type
;
2261 wanted_type_name
= fci
->types
[length_chars_val
].name
;
2266 if (first_wanted_type
!= 0)
2267 check_format_types (first_wanted_type
);
2270 if (format_chars
- orig_format_chars
!= format_length
)
2271 warning (OPT_Wformat_contains_nul
, "embedded %<\\0%> in format");
2272 if (info
->first_arg_num
!= 0 && params
!= 0
2273 && has_operand_number
<= 0)
2275 res
->number_other
--;
2276 res
->number_extra_args
++;
2278 if (has_operand_number
> 0)
2279 finish_dollar_format_checking (res
, fki
->flags
& (int) FMT_FLAG_DOLLAR_GAP_POINTER_OK
);
2283 /* Check the argument types from a single format conversion (possibly
2284 including width and precision arguments). */
2286 check_format_types (format_wanted_type
*types
)
2288 for (; types
!= 0; types
= types
->next
)
2298 wanted_type
= types
->wanted_type
;
2299 arg_num
= types
->arg_num
;
2301 /* The following should not occur here. */
2302 gcc_assert (wanted_type
);
2303 gcc_assert (wanted_type
!= void_type_node
|| types
->pointer_count
);
2305 if (types
->pointer_count
== 0)
2306 wanted_type
= lang_hooks
.types
.type_promotes_to (wanted_type
);
2308 wanted_type
= TYPE_MAIN_VARIANT (wanted_type
);
2310 cur_param
= types
->param
;
2313 format_type_warning (types
, wanted_type
, NULL
);
2317 cur_type
= TREE_TYPE (cur_param
);
2318 if (cur_type
== error_mark_node
)
2320 orig_cur_type
= cur_type
;
2323 STRIP_NOPS (cur_param
);
2325 /* Check the types of any additional pointer arguments
2326 that precede the "real" argument. */
2327 for (i
= 0; i
< types
->pointer_count
; ++i
)
2329 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
2331 cur_type
= TREE_TYPE (cur_type
);
2332 if (cur_type
== error_mark_node
)
2335 /* Check for writing through a NULL pointer. */
2336 if (types
->writing_in_flag
2339 && integer_zerop (cur_param
))
2340 warning (OPT_Wformat_
, "writing through null pointer "
2341 "(argument %d)", arg_num
);
2343 /* Check for reading through a NULL pointer. */
2344 if (types
->reading_from_flag
2347 && integer_zerop (cur_param
))
2348 warning (OPT_Wformat_
, "reading through null pointer "
2349 "(argument %d)", arg_num
);
2351 if (cur_param
!= 0 && TREE_CODE (cur_param
) == ADDR_EXPR
)
2352 cur_param
= TREE_OPERAND (cur_param
, 0);
2356 /* See if this is an attempt to write into a const type with
2357 scanf or with printf "%n". Note: the writing in happens
2358 at the first indirection only, if for example
2359 void * const * is passed to scanf %p; passing
2360 const void ** is simply passing an incompatible type. */
2361 if (types
->writing_in_flag
2363 && (TYPE_READONLY (cur_type
)
2365 && (CONSTANT_CLASS_P (cur_param
)
2366 || (DECL_P (cur_param
)
2367 && TREE_READONLY (cur_param
))))))
2368 warning (OPT_Wformat_
, "writing into constant object "
2369 "(argument %d)", arg_num
);
2371 /* If there are extra type qualifiers beyond the first
2372 indirection, then this makes the types technically
2376 && (TYPE_READONLY (cur_type
)
2377 || TYPE_VOLATILE (cur_type
)
2378 || TYPE_ATOMIC (cur_type
)
2379 || TYPE_RESTRICT (cur_type
)))
2380 warning (OPT_Wformat_
, "extra type qualifiers in format "
2381 "argument (argument %d)",
2387 format_type_warning (types
, wanted_type
, orig_cur_type
);
2392 if (i
< types
->pointer_count
)
2395 cur_type
= TYPE_MAIN_VARIANT (cur_type
);
2397 /* Check whether the argument type is a character type. This leniency
2398 only applies to certain formats, flagged with 'c'.
2400 if (types
->char_lenient_flag
)
2401 char_type_flag
= (cur_type
== char_type_node
2402 || cur_type
== signed_char_type_node
2403 || cur_type
== unsigned_char_type_node
);
2405 /* Check the type of the "real" argument, if there's a type we want. */
2406 if (lang_hooks
.types_compatible_p (wanted_type
, cur_type
))
2408 /* If we want 'void *', allow any pointer type.
2409 (Anything else would already have got a warning.)
2410 With -Wpedantic, only allow pointers to void and to character
2412 if (wanted_type
== void_type_node
2413 && (!pedantic
|| (i
== 1 && char_type_flag
)))
2415 /* Don't warn about differences merely in signedness, unless
2416 -Wpedantic. With -Wpedantic, warn if the type is a pointer
2417 target and not a character type, and for character types at
2418 a second level of indirection. */
2419 if (TREE_CODE (wanted_type
) == INTEGER_TYPE
2420 && TREE_CODE (cur_type
) == INTEGER_TYPE
2421 && (!pedantic
|| i
== 0 || (i
== 1 && char_type_flag
))
2422 && (TYPE_UNSIGNED (wanted_type
)
2423 ? wanted_type
== c_common_unsigned_type (cur_type
)
2424 : wanted_type
== c_common_signed_type (cur_type
)))
2426 /* Likewise, "signed char", "unsigned char" and "char" are
2427 equivalent but the above test won't consider them equivalent. */
2428 if (wanted_type
== char_type_node
2429 && (!pedantic
|| i
< 2)
2432 if (types
->scalar_identity_flag
2433 && (TREE_CODE (cur_type
) == TREE_CODE (wanted_type
)
2434 || (INTEGRAL_TYPE_P (cur_type
)
2435 && INTEGRAL_TYPE_P (wanted_type
)))
2436 && TYPE_PRECISION (cur_type
) == TYPE_PRECISION (wanted_type
))
2438 /* Now we have a type mismatch. */
2439 format_type_warning (types
, wanted_type
, orig_cur_type
);
2444 /* Give a warning about a format argument of different type from that
2445 expected. WANTED_TYPE is the type the argument should have, possibly
2446 stripped of pointer dereferences. The description (such as "field
2447 precision"), the placement in the format string, a possibly more
2448 friendly name of WANTED_TYPE, and the number of pointer dereferences
2449 are taken from TYPE. ARG_TYPE is the type of the actual argument,
2450 or NULL if it is missing. */
2452 format_type_warning (format_wanted_type
*type
, tree wanted_type
, tree arg_type
)
2454 int kind
= type
->kind
;
2455 const char *wanted_type_name
= type
->wanted_type_name
;
2456 const char *format_start
= type
->format_start
;
2457 int format_length
= type
->format_length
;
2458 int pointer_count
= type
->pointer_count
;
2459 int arg_num
= type
->arg_num
;
2462 /* If ARG_TYPE is a typedef with a misleading name (for example,
2463 size_t but not the standard size_t expected by printf %zu), avoid
2464 printing the typedef name. */
2465 if (wanted_type_name
2467 && TYPE_NAME (arg_type
)
2468 && TREE_CODE (TYPE_NAME (arg_type
)) == TYPE_DECL
2469 && DECL_NAME (TYPE_NAME (arg_type
))
2470 && !strcmp (wanted_type_name
,
2471 lang_hooks
.decl_printable_name (TYPE_NAME (arg_type
), 2)))
2472 arg_type
= TYPE_MAIN_VARIANT (arg_type
);
2473 /* The format type and name exclude any '*' for pointers, so those
2474 must be formatted manually. For all the types we currently have,
2475 this is adequate, but formats taking pointers to functions or
2476 arrays would require the full type to be built up in order to
2477 print it with %T. */
2478 p
= (char *) alloca (pointer_count
+ 2);
2479 if (pointer_count
== 0)
2481 else if (c_dialect_cxx ())
2483 memset (p
, '*', pointer_count
);
2484 p
[pointer_count
] = 0;
2489 memset (p
+ 1, '*', pointer_count
);
2490 p
[pointer_count
+ 1] = 0;
2493 if (wanted_type_name
)
2496 warning (OPT_Wformat_
, "%s %<%s%.*s%> expects argument of type %<%s%s%>, "
2497 "but argument %d has type %qT",
2498 gettext (kind_descriptions
[kind
]),
2499 (kind
== CF_KIND_FORMAT
? "%" : ""),
2500 format_length
, format_start
,
2501 wanted_type_name
, p
, arg_num
, arg_type
);
2503 warning (OPT_Wformat_
, "%s %<%s%.*s%> expects a matching %<%s%s%> argument",
2504 gettext (kind_descriptions
[kind
]),
2505 (kind
== CF_KIND_FORMAT
? "%" : ""),
2506 format_length
, format_start
, wanted_type_name
, p
);
2511 warning (OPT_Wformat_
, "%s %<%s%.*s%> expects argument of type %<%T%s%>, "
2512 "but argument %d has type %qT",
2513 gettext (kind_descriptions
[kind
]),
2514 (kind
== CF_KIND_FORMAT
? "%" : ""),
2515 format_length
, format_start
,
2516 wanted_type
, p
, arg_num
, arg_type
);
2518 warning (OPT_Wformat_
, "%s %<%s%.*s%> expects a matching %<%T%s%> argument",
2519 gettext (kind_descriptions
[kind
]),
2520 (kind
== CF_KIND_FORMAT
? "%" : ""),
2521 format_length
, format_start
, wanted_type
, p
);
2526 /* Given a format_char_info array FCI, and a character C, this function
2527 returns the index into the conversion_specs where that specifier's
2528 data is located. The character must exist. */
2530 find_char_info_specifier_index (const format_char_info
*fci
, int c
)
2534 for (i
= 0; fci
->format_chars
; i
++, fci
++)
2535 if (strchr (fci
->format_chars
, c
))
2538 /* We shouldn't be looking for a non-existent specifier. */
2542 /* Given a format_length_info array FLI, and a character C, this
2543 function returns the index into the conversion_specs where that
2544 modifier's data is located. The character must exist. */
2546 find_length_info_modifier_index (const format_length_info
*fli
, int c
)
2550 for (i
= 0; fli
->name
; i
++, fli
++)
2551 if (strchr (fli
->name
, c
))
2554 /* We shouldn't be looking for a non-existent modifier. */
2558 /* Determine the type of HOST_WIDE_INT in the code being compiled for
2559 use in GCC's __asm_fprintf__ custom format attribute. You must
2560 have set dynamic_format_types before calling this function. */
2562 init_dynamic_asm_fprintf_info (void)
2568 format_length_info
*new_asm_fprintf_length_specs
;
2571 /* Find the underlying type for HOST_WIDE_INT. For the %w
2572 length modifier to work, one must have issued: "typedef
2573 HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code
2574 prior to using that modifier. */
2575 hwi
= maybe_get_identifier ("__gcc_host_wide_int__");
2578 error ("%<__gcc_host_wide_int__%> is not defined as a type");
2581 hwi
= identifier_global_value (hwi
);
2582 if (!hwi
|| TREE_CODE (hwi
) != TYPE_DECL
)
2584 error ("%<__gcc_host_wide_int__%> is not defined as a type");
2587 hwi
= DECL_ORIGINAL_TYPE (hwi
);
2589 if (hwi
!= long_integer_type_node
&& hwi
!= long_long_integer_type_node
)
2591 error ("%<__gcc_host_wide_int__%> is not defined as %<long%>"
2592 " or %<long long%>");
2596 /* Create a new (writable) copy of asm_fprintf_length_specs. */
2597 new_asm_fprintf_length_specs
= (format_length_info
*)
2598 xmemdup (asm_fprintf_length_specs
,
2599 sizeof (asm_fprintf_length_specs
),
2600 sizeof (asm_fprintf_length_specs
));
2602 /* HOST_WIDE_INT must be one of 'long' or 'long long'. */
2603 i
= find_length_info_modifier_index (new_asm_fprintf_length_specs
, 'w');
2604 if (hwi
== long_integer_type_node
)
2605 new_asm_fprintf_length_specs
[i
].index
= FMT_LEN_l
;
2606 else if (hwi
== long_long_integer_type_node
)
2607 new_asm_fprintf_length_specs
[i
].index
= FMT_LEN_ll
;
2611 /* Assign the new data for use. */
2612 dynamic_format_types
[asm_fprintf_format_type
].length_char_specs
=
2613 new_asm_fprintf_length_specs
;
2617 /* Determine the type of a "locus" in the code being compiled for use
2618 in GCC's __gcc_gfc__ custom format attribute. You must have set
2619 dynamic_format_types before calling this function. */
2621 init_dynamic_gfc_info (void)
2627 static format_char_info
*gfc_fci
;
2629 /* For the GCC __gcc_gfc__ custom format specifier to work, one
2630 must have declared 'locus' prior to using this attribute. If
2631 we haven't seen this declarations then you shouldn't use the
2632 specifier requiring that type. */
2633 if ((locus
= maybe_get_identifier ("locus")))
2635 locus
= identifier_global_value (locus
);
2638 if (TREE_CODE (locus
) != TYPE_DECL
2639 || TREE_TYPE (locus
) == error_mark_node
)
2641 error ("%<locus%> is not defined as a type");
2645 locus
= TREE_TYPE (locus
);
2649 /* Assign the new data for use. */
2651 /* Handle the __gcc_gfc__ format specifics. */
2653 dynamic_format_types
[gcc_gfc_format_type
].conversion_specs
=
2654 gfc_fci
= (format_char_info
*)
2655 xmemdup (gcc_gfc_char_table
,
2656 sizeof (gcc_gfc_char_table
),
2657 sizeof (gcc_gfc_char_table
));
2660 const unsigned i
= find_char_info_specifier_index (gfc_fci
, 'L');
2661 gfc_fci
[i
].types
[0].type
= &locus
;
2662 gfc_fci
[i
].pointer_count
= 1;
2667 /* Determine the types of "tree" and "location_t" in the code being
2668 compiled for use in GCC's diagnostic custom format attributes. You
2669 must have set dynamic_format_types before calling this function. */
2671 init_dynamic_diag_info (void)
2673 static tree t
, loc
, hwi
;
2675 if (!loc
|| !t
|| !hwi
)
2677 static format_char_info
*diag_fci
, *tdiag_fci
, *cdiag_fci
, *cxxdiag_fci
;
2678 static format_length_info
*diag_ls
;
2681 /* For the GCC-diagnostics custom format specifiers to work, one
2682 must have declared 'tree' and/or 'location_t' prior to using
2683 those attributes. If we haven't seen these declarations then
2684 you shouldn't use the specifiers requiring these types.
2685 However we don't force a hard ICE because we may see only one
2686 or the other type. */
2687 if ((loc
= maybe_get_identifier ("location_t")))
2689 loc
= identifier_global_value (loc
);
2692 if (TREE_CODE (loc
) != TYPE_DECL
)
2694 error ("%<location_t%> is not defined as a type");
2698 loc
= TREE_TYPE (loc
);
2702 /* We need to grab the underlying 'union tree_node' so peek into
2703 an extra type level. */
2704 if ((t
= maybe_get_identifier ("tree")))
2706 t
= identifier_global_value (t
);
2709 if (TREE_CODE (t
) != TYPE_DECL
)
2711 error ("%<tree%> is not defined as a type");
2714 else if (TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
)
2716 error ("%<tree%> is not defined as a pointer type");
2720 t
= TREE_TYPE (TREE_TYPE (t
));
2724 /* Find the underlying type for HOST_WIDE_INT. For the %w
2725 length modifier to work, one must have issued: "typedef
2726 HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code
2727 prior to using that modifier. */
2728 if ((hwi
= maybe_get_identifier ("__gcc_host_wide_int__")))
2730 hwi
= identifier_global_value (hwi
);
2733 if (TREE_CODE (hwi
) != TYPE_DECL
)
2735 error ("%<__gcc_host_wide_int__%> is not defined as a type");
2740 hwi
= DECL_ORIGINAL_TYPE (hwi
);
2742 if (hwi
!= long_integer_type_node
2743 && hwi
!= long_long_integer_type_node
)
2745 error ("%<__gcc_host_wide_int__%> is not defined"
2746 " as %<long%> or %<long long%>");
2753 /* Assign the new data for use. */
2755 /* All the GCC diag formats use the same length specs. */
2757 dynamic_format_types
[gcc_diag_format_type
].length_char_specs
=
2758 dynamic_format_types
[gcc_tdiag_format_type
].length_char_specs
=
2759 dynamic_format_types
[gcc_cdiag_format_type
].length_char_specs
=
2760 dynamic_format_types
[gcc_cxxdiag_format_type
].length_char_specs
=
2761 diag_ls
= (format_length_info
*)
2762 xmemdup (gcc_diag_length_specs
,
2763 sizeof (gcc_diag_length_specs
),
2764 sizeof (gcc_diag_length_specs
));
2767 /* HOST_WIDE_INT must be one of 'long' or 'long long'. */
2768 i
= find_length_info_modifier_index (diag_ls
, 'w');
2769 if (hwi
== long_integer_type_node
)
2770 diag_ls
[i
].index
= FMT_LEN_l
;
2771 else if (hwi
== long_long_integer_type_node
)
2772 diag_ls
[i
].index
= FMT_LEN_ll
;
2777 /* Handle the __gcc_diag__ format specifics. */
2779 dynamic_format_types
[gcc_diag_format_type
].conversion_specs
=
2780 diag_fci
= (format_char_info
*)
2781 xmemdup (gcc_diag_char_table
,
2782 sizeof (gcc_diag_char_table
),
2783 sizeof (gcc_diag_char_table
));
2786 i
= find_char_info_specifier_index (diag_fci
, 'K');
2787 diag_fci
[i
].types
[0].type
= &t
;
2788 diag_fci
[i
].pointer_count
= 1;
2791 /* Handle the __gcc_tdiag__ format specifics. */
2793 dynamic_format_types
[gcc_tdiag_format_type
].conversion_specs
=
2794 tdiag_fci
= (format_char_info
*)
2795 xmemdup (gcc_tdiag_char_table
,
2796 sizeof (gcc_tdiag_char_table
),
2797 sizeof (gcc_tdiag_char_table
));
2800 /* All specifiers taking a tree share the same struct. */
2801 i
= find_char_info_specifier_index (tdiag_fci
, 'D');
2802 tdiag_fci
[i
].types
[0].type
= &t
;
2803 tdiag_fci
[i
].pointer_count
= 1;
2804 i
= find_char_info_specifier_index (tdiag_fci
, 'K');
2805 tdiag_fci
[i
].types
[0].type
= &t
;
2806 tdiag_fci
[i
].pointer_count
= 1;
2809 /* Handle the __gcc_cdiag__ format specifics. */
2811 dynamic_format_types
[gcc_cdiag_format_type
].conversion_specs
=
2812 cdiag_fci
= (format_char_info
*)
2813 xmemdup (gcc_cdiag_char_table
,
2814 sizeof (gcc_cdiag_char_table
),
2815 sizeof (gcc_cdiag_char_table
));
2818 /* All specifiers taking a tree share the same struct. */
2819 i
= find_char_info_specifier_index (cdiag_fci
, 'D');
2820 cdiag_fci
[i
].types
[0].type
= &t
;
2821 cdiag_fci
[i
].pointer_count
= 1;
2822 i
= find_char_info_specifier_index (cdiag_fci
, 'K');
2823 cdiag_fci
[i
].types
[0].type
= &t
;
2824 cdiag_fci
[i
].pointer_count
= 1;
2827 /* Handle the __gcc_cxxdiag__ format specifics. */
2829 dynamic_format_types
[gcc_cxxdiag_format_type
].conversion_specs
=
2830 cxxdiag_fci
= (format_char_info
*)
2831 xmemdup (gcc_cxxdiag_char_table
,
2832 sizeof (gcc_cxxdiag_char_table
),
2833 sizeof (gcc_cxxdiag_char_table
));
2836 /* All specifiers taking a tree share the same struct. */
2837 i
= find_char_info_specifier_index (cxxdiag_fci
, 'D');
2838 cxxdiag_fci
[i
].types
[0].type
= &t
;
2839 cxxdiag_fci
[i
].pointer_count
= 1;
2840 i
= find_char_info_specifier_index (cxxdiag_fci
, 'K');
2841 cxxdiag_fci
[i
].types
[0].type
= &t
;
2842 cxxdiag_fci
[i
].pointer_count
= 1;
2847 #ifdef TARGET_FORMAT_TYPES
2848 extern const format_kind_info TARGET_FORMAT_TYPES
[];
2851 #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
2852 extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES
[];
2854 #ifdef TARGET_OVERRIDES_FORMAT_INIT
2855 extern void TARGET_OVERRIDES_FORMAT_INIT (void);
2858 /* Attributes such as "printf" are equivalent to those such as
2859 "gnu_printf" unless this is overridden by a target. */
2860 static const target_ovr_attr gnu_target_overrides_format_attributes
[] =
2862 { "gnu_printf", "printf" },
2863 { "gnu_scanf", "scanf" },
2864 { "gnu_strftime", "strftime" },
2865 { "gnu_strfmon", "strfmon" },
2869 /* Translate to unified attribute name. This is used in decode_format_type and
2870 decode_format_attr. In attr_name the user specified argument is passed. It
2871 returns the unified format name from TARGET_OVERRIDES_FORMAT_ATTRIBUTES
2872 or the attr_name passed to this function, if there is no matching entry. */
2874 convert_format_name_to_system_name (const char *attr_name
)
2878 if (attr_name
== NULL
|| *attr_name
== 0
2879 || strncmp (attr_name
, "gcc_", 4) == 0)
2881 #ifdef TARGET_OVERRIDES_FORMAT_INIT
2882 TARGET_OVERRIDES_FORMAT_INIT ();
2885 #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
2886 /* Check if format attribute is overridden by target. */
2887 if (TARGET_OVERRIDES_FORMAT_ATTRIBUTES
!= NULL
2888 && TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
> 0)
2890 for (i
= 0; i
< TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
; ++i
)
2892 if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES
[i
].named_attr_src
,
2895 if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES
[i
].named_attr_dst
,
2897 return TARGET_OVERRIDES_FORMAT_ATTRIBUTES
[i
].named_attr_src
;
2901 /* Otherwise default to gnu format. */
2903 gnu_target_overrides_format_attributes
[i
].named_attr_src
!= NULL
;
2906 if (cmp_attribs (gnu_target_overrides_format_attributes
[i
].named_attr_src
,
2909 if (cmp_attribs (gnu_target_overrides_format_attributes
[i
].named_attr_dst
,
2911 return gnu_target_overrides_format_attributes
[i
].named_attr_src
;
2917 /* Return true if TATTR_NAME and ATTR_NAME are the same format attribute,
2918 counting "name" and "__name__" as the same, false otherwise. */
2920 cmp_attribs (const char *tattr_name
, const char *attr_name
)
2922 int alen
= strlen (attr_name
);
2923 int slen
= (tattr_name
? strlen (tattr_name
) : 0);
2924 if (alen
> 4 && attr_name
[0] == '_' && attr_name
[1] == '_'
2925 && attr_name
[alen
- 1] == '_' && attr_name
[alen
- 2] == '_')
2930 if (alen
!= slen
|| strncmp (tattr_name
, attr_name
, alen
) != 0)
2935 /* Handle a "format" attribute; arguments as in
2936 struct attribute_spec.handler. */
2938 handle_format_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2939 int flags
, bool *no_add_attrs
)
2942 function_format_info info
;
2944 #ifdef TARGET_FORMAT_TYPES
2945 /* If the target provides additional format types, we need to
2946 add them to FORMAT_TYPES at first use. */
2947 if (TARGET_FORMAT_TYPES
!= NULL
&& !dynamic_format_types
)
2949 dynamic_format_types
= XNEWVEC (format_kind_info
,
2950 n_format_types
+ TARGET_N_FORMAT_TYPES
);
2951 memcpy (dynamic_format_types
, format_types_orig
,
2952 sizeof (format_types_orig
));
2953 memcpy (&dynamic_format_types
[n_format_types
], TARGET_FORMAT_TYPES
,
2954 TARGET_N_FORMAT_TYPES
* sizeof (dynamic_format_types
[0]));
2956 format_types
= dynamic_format_types
;
2957 /* Provide a reference for the first potential external type. */
2958 first_target_format_type
= n_format_types
;
2959 n_format_types
+= TARGET_N_FORMAT_TYPES
;
2963 if (!decode_format_attr (args
, &info
, 0))
2965 *no_add_attrs
= true;
2969 if (prototype_p (type
))
2971 if (!check_format_string (type
, info
.format_num
, flags
,
2972 no_add_attrs
, info
.format_type
))
2975 if (info
.first_arg_num
!= 0)
2977 unsigned HOST_WIDE_INT arg_num
= 1;
2978 function_args_iterator iter
;
2981 /* Verify that first_arg_num points to the last arg,
2983 FOREACH_FUNCTION_ARGS (type
, arg_type
, iter
)
2986 if (arg_num
!= info
.first_arg_num
)
2988 if (!(flags
& (int) ATTR_FLAG_BUILT_IN
))
2989 error ("args to be formatted is not %<...%>");
2990 *no_add_attrs
= true;
2996 /* Check if this is a strftime variant. Just for this variant
2997 FMT_FLAG_ARG_CONVERT is not set. */
2998 if ((format_types
[info
.format_type
].flags
& (int) FMT_FLAG_ARG_CONVERT
) == 0
2999 && info
.first_arg_num
!= 0)
3001 error ("strftime formats cannot format arguments");
3002 *no_add_attrs
= true;
3006 /* If this is a custom GCC-internal format type, we have to
3007 initialize certain bits at runtime. */
3008 if (info
.format_type
== asm_fprintf_format_type
3009 || info
.format_type
== gcc_gfc_format_type
3010 || info
.format_type
== gcc_diag_format_type
3011 || info
.format_type
== gcc_tdiag_format_type
3012 || info
.format_type
== gcc_cdiag_format_type
3013 || info
.format_type
== gcc_cxxdiag_format_type
)
3015 /* Our first time through, we have to make sure that our
3016 format_type data is allocated dynamically and is modifiable. */
3017 if (!dynamic_format_types
)
3018 format_types
= dynamic_format_types
= (format_kind_info
*)
3019 xmemdup (format_types_orig
, sizeof (format_types_orig
),
3020 sizeof (format_types_orig
));
3022 /* If this is format __asm_fprintf__, we have to initialize
3023 GCC's notion of HOST_WIDE_INT for checking %wd. */
3024 if (info
.format_type
== asm_fprintf_format_type
)
3025 init_dynamic_asm_fprintf_info ();
3026 /* If this is format __gcc_gfc__, we have to initialize GCC's
3027 notion of 'locus' at runtime for %L. */
3028 else if (info
.format_type
== gcc_gfc_format_type
)
3029 init_dynamic_gfc_info ();
3030 /* If this is one of the diagnostic attributes, then we have to
3031 initialize 'location_t' and 'tree' at runtime. */
3032 else if (info
.format_type
== gcc_diag_format_type
3033 || info
.format_type
== gcc_tdiag_format_type
3034 || info
.format_type
== gcc_cdiag_format_type
3035 || info
.format_type
== gcc_cxxdiag_format_type
)
3036 init_dynamic_diag_info ();