/* Check calls to formatted I/O functions (-Wformat).
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
!= char_type_node))
{
if (!(flags & (int) ATTR_FLAG_BUILT_IN))
- error ("format string arg not a string type");
+ error ("format string argument not a string type");
*no_add_attrs = true;
return false;
}
return true;
}
-/* Strip any conversions from the expression, verify it is a constant,
- and store its value. If validated_p is true, abort on errors.
+/* Verify EXPR is a constant, and store its value.
+ If validated_p is true, abort on errors.
Returns true on success, false otherwise. */
static bool
-get_constant(tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
+get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
{
- while (TREE_CODE (expr) == NOP_EXPR
- || TREE_CODE (expr) == CONVERT_EXPR
- || TREE_CODE (expr) == NON_LVALUE_EXPR)
- expr = TREE_OPERAND (expr, 0);
-
if (TREE_CODE (expr) != INTEGER_CST || TREE_INT_CST_HIGH (expr) != 0)
{
- if (validated_p)
- abort ();
+ gcc_assert (!validated_p);
return false;
}
if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
{
- if (validated_p)
- abort ();
+ gcc_assert (!validated_p);
error ("unrecognized format specifier");
return false;
}
if (info->format_type == format_type_error)
{
- if (validated_p)
- abort ();
- warning ("%qs is an unrecognized format function type", p);
+ gcc_assert (!validated_p);
+ warning ("%qE is an unrecognized format function type",
+ format_type_id);
return false;
}
}
if (!get_constant (first_arg_num_expr, &info->first_arg_num, validated_p))
{
- error ("'...' has invalid operand number");
+ error ("%<...%> has invalid operand number");
return false;
}
if (info->first_arg_num != 0 && info->first_arg_num <= info->format_num)
{
- if (validated_p)
- abort ();
- error ("format string arg follows the args to be formatted");
+ gcc_assert (!validated_p);
+ error ("format string argument follows the args to be formatted");
return false;
}
or inheriting from, for the purpose of format features supported. */
#define CPLUSPLUS_STD_VER STD_C94
/* The C standard version we are checking formats against when pedantic. */
-#define C_STD_VER ((int)(c_dialect_cxx () \
- ? CPLUSPLUS_STD_VER \
- : (flag_isoc99 \
- ? STD_C99 \
+#define C_STD_VER ((int) (c_dialect_cxx () \
+ ? CPLUSPLUS_STD_VER \
+ : (flag_isoc99 \
+ ? STD_C99 \
: (flag_isoc94 ? STD_C94 : STD_C89))))
/* The name to give to the standard version we are warning about when
pedantic. FEATURE_VER is the version in which the feature warned out
: "ISO C90"))
/* Adjust a C standard version, which may be STD_C9L, to account for
-Wno-long-long. Returns other standard versions unchanged. */
-#define ADJ_STD(VER) ((int)((VER) == STD_C9L \
+#define ADJ_STD(VER) ((int) ((VER) == STD_C9L \
? (warn_long_long ? STD_C99 : STD_C89) \
: (VER)))
static const format_flag_spec printf_flag_specs[] =
{
- { ' ', 0, 0, N_("` ' flag"), N_("the ` ' printf flag"), STD_C89 },
- { '+', 0, 0, N_("`+' flag"), N_("the `+' printf flag"), STD_C89 },
- { '#', 0, 0, N_("`#' flag"), N_("the `#' printf flag"), STD_C89 },
- { '0', 0, 0, N_("`0' flag"), N_("the `0' printf flag"), STD_C89 },
- { '-', 0, 0, N_("`-' flag"), N_("the `-' printf flag"), STD_C89 },
- { '\'', 0, 0, N_("`'' flag"), N_("the `'' printf flag"), STD_EXT },
- { 'I', 0, 0, N_("`I' flag"), N_("the `I' printf flag"), STD_EXT },
+ { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89 },
+ { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89 },
+ { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89 },
+ { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89 },
+ { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89 },
+ { '\'', 0, 0, N_("''' flag"), N_("the ''' printf flag"), STD_EXT },
+ { 'I', 0, 0, N_("'I' flag"), N_("the 'I' printf flag"), STD_EXT },
{ 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
{ 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
static const format_flag_spec asm_fprintf_flag_specs[] =
{
- { ' ', 0, 0, N_("` ' flag"), N_("the ` ' printf flag"), STD_C89 },
- { '+', 0, 0, N_("`+' flag"), N_("the `+' printf flag"), STD_C89 },
- { '#', 0, 0, N_("`#' flag"), N_("the `#' printf flag"), STD_C89 },
- { '0', 0, 0, N_("`0' flag"), N_("the `0' printf flag"), STD_C89 },
- { '-', 0, 0, N_("`-' flag"), N_("the `-' printf flag"), STD_C89 },
+ { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89 },
+ { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89 },
+ { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89 },
+ { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89 },
+ { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89 },
{ 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
{ 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
static const format_flag_spec gcc_diag_flag_specs[] =
{
- { 'q', 0, 0, N_("`q' flag"), N_("the `q' diagnostic flag"), STD_C89 },
+ { 'q', 0, 0, N_("'q' flag"), N_("the 'q' diagnostic flag"), STD_C89 },
{ 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
{ 0, 0, 0, NULL, NULL, 0 }
static const format_flag_spec gcc_cxxdiag_flag_specs[] =
{
- { '+', 0, 0, N_("`+' flag"), N_("the `+' printf flag"), STD_C89 },
- { '#', 0, 0, N_("`#' flag"), N_("the `#' printf flag"), STD_C89 },
- { 'q', 0, 0, N_("`q' flag"), N_("the `q' diagnostic flag"), STD_C89 },
+ { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89 },
+ { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89 },
+ { 'q', 0, 0, N_("'q' flag"), N_("the 'q' diagnostic flag"), STD_C89 },
{ 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
{ 0, 0, 0, NULL, NULL, 0 }
static const format_flag_spec scanf_flag_specs[] =
{
{ '*', 0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89 },
- { 'a', 0, 0, N_("`a' flag"), N_("the `a' scanf flag"), STD_EXT },
+ { 'a', 0, 0, N_("'a' flag"), N_("the 'a' scanf flag"), STD_EXT },
{ 'w', 0, 0, N_("field width"), N_("field width in scanf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in scanf format"), STD_C89 },
- { '\'', 0, 0, N_("`'' flag"), N_("the `'' scanf flag"), STD_EXT },
- { 'I', 0, 0, N_("`I' flag"), N_("the `I' scanf flag"), STD_EXT },
+ { '\'', 0, 0, N_("''' flag"), N_("the ''' scanf flag"), STD_EXT },
+ { 'I', 0, 0, N_("'I' flag"), N_("the 'I' scanf flag"), STD_EXT },
{ 0, 0, 0, NULL, NULL, 0 }
};
static const format_flag_spec strftime_flag_specs[] =
{
- { '_', 0, 0, N_("`_' flag"), N_("the `_' strftime flag"), STD_EXT },
- { '-', 0, 0, N_("`-' flag"), N_("the `-' strftime flag"), STD_EXT },
- { '0', 0, 0, N_("`0' flag"), N_("the `0' strftime flag"), STD_EXT },
- { '^', 0, 0, N_("`^' flag"), N_("the `^' strftime flag"), STD_EXT },
- { '#', 0, 0, N_("`#' flag"), N_("the `#' strftime flag"), STD_EXT },
+ { '_', 0, 0, N_("'_' flag"), N_("the '_' strftime flag"), STD_EXT },
+ { '-', 0, 0, N_("'-' flag"), N_("the '-' strftime flag"), STD_EXT },
+ { '0', 0, 0, N_("'0' flag"), N_("the '0' strftime flag"), STD_EXT },
+ { '^', 0, 0, N_("'^' flag"), N_("the '^' strftime flag"), STD_EXT },
+ { '#', 0, 0, N_("'#' flag"), N_("the '#' strftime flag"), STD_EXT },
{ 'w', 0, 0, N_("field width"), N_("field width in strftime format"), STD_EXT },
- { 'E', 0, 0, N_("`E' modifier"), N_("the `E' strftime modifier"), STD_C99 },
- { 'O', 0, 0, N_("`O' modifier"), N_("the `O' strftime modifier"), STD_C99 },
- { 'O', 'o', 0, NULL, N_("the `O' modifier"), STD_EXT },
+ { 'E', 0, 0, N_("'E' modifier"), N_("the 'E' strftime modifier"), STD_C99 },
+ { 'O', 0, 0, N_("'O' modifier"), N_("the 'O' strftime modifier"), STD_C99 },
+ { 'O', 'o', 0, NULL, N_("the 'O' modifier"), STD_EXT },
{ 0, 0, 0, NULL, NULL, 0 }
};
static const format_flag_spec strfmon_flag_specs[] =
{
{ '=', 0, 1, N_("fill character"), N_("fill character in strfmon format"), STD_C89 },
- { '^', 0, 0, N_("`^' flag"), N_("the `^' strfmon flag"), STD_C89 },
- { '+', 0, 0, N_("`+' flag"), N_("the `+' strfmon flag"), STD_C89 },
- { '(', 0, 0, N_("`(' flag"), N_("the `(' strfmon flag"), STD_C89 },
- { '!', 0, 0, N_("`!' flag"), N_("the `!' strfmon flag"), STD_C89 },
- { '-', 0, 0, N_("`-' flag"), N_("the `-' strfmon flag"), STD_C89 },
+ { '^', 0, 0, N_("'^' flag"), N_("the '^' strfmon flag"), STD_C89 },
+ { '+', 0, 0, N_("'+' flag"), N_("the '+' strfmon flag"), STD_C89 },
+ { '(', 0, 0, N_("'(' flag"), N_("the '(' strfmon flag"), STD_C89 },
+ { '!', 0, 0, N_("'!' flag"), N_("the '!' strfmon flag"), STD_C89 },
+ { '-', 0, 0, N_("'-' flag"), N_("the '-' strfmon flag"), STD_C89 },
{ 'w', 0, 0, N_("field width"), N_("field width in strfmon format"), STD_C89 },
{ '#', 0, 0, N_("left precision"), N_("left precision in strfmon format"), STD_C89 },
{ 'p', 0, 0, N_("right precision"), N_("right precision in strfmon format"), STD_C89 },
/* These will require a "tree" at runtime. */
{ "ADEFJTV",0,STD_C89,{ T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q+#", "", NULL },
- /* These accept either an `int' or an `enum tree_code' (which is handled as an `int'.) */
+ /* These accept either an 'int' or an 'enum tree_code' (which is handled as an 'int'.) */
{ "CLOPQ",0,STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "", NULL },
{ "<>'", 0, STD_C89, NOARGUMENTS, "", "", NULL },
int argnum;
int overflow_flag;
const char *fcp = *format;
- if (! ISDIGIT (*fcp))
+ if (!ISDIGIT (*fcp))
{
if (dollar_needed)
{
for (i = 1; i < argnum && *param_ptr != 0; i++)
*param_ptr = TREE_CHAIN (*param_ptr);
- if (*param_ptr == 0)
- {
- /* This case shouldn't be caught here. */
- abort ();
- }
+ /* This case shouldn't be caught here. */
+ gcc_assert (*param_ptr);
}
else
*param_ptr = 0;
else if (spec[i].predicate == 0)
return &spec[i];
}
- if (predicates == NULL)
- abort ();
- else
- return NULL;
+ gcc_assert (predicates);
+ return NULL;
}
if (array_size != 0)
{
/* Variable length arrays can't be initialized. */
- if (TREE_CODE (array_size) != INTEGER_CST)
- abort ();
+ gcc_assert (TREE_CODE (array_size) == INTEGER_CST);
+
if (host_integerp (array_size, 0))
{
HOST_WIDE_INT array_size_value = TREE_INT_CST_LOW (array_size);
if (format_chars[1] == 's' || format_chars[1] == 'S'
|| format_chars[1] == '[')
{
- /* `a' is used as a flag. */
+ /* 'a' is used as a flag. */
i = strlen (flag_chars);
flag_chars[i++] = 'a';
flag_chars[i] = 0;
++fci;
if (fci->format_chars == 0)
{
- if (ISGRAPH(format_char))
+ if (ISGRAPH (format_char))
warning ("unknown conversion type character %qc in format",
format_char);
else
arg_num = types->arg_num;
/* The following should not occur here. */
- if (wanted_type == 0)
- abort ();
- if (wanted_type == void_type_node && types->pointer_count == 0)
- abort ();
+ gcc_assert (wanted_type);
+ gcc_assert (wanted_type != void_type_node || types->pointer_count);
if (types->pointer_count == 0)
wanted_type = lang_hooks.types.type_promotes_to (wanted_type);
&& i == 0
&& cur_param != 0
&& integer_zerop (cur_param))
- warning ("writing through null pointer (arg %d)",
+ warning ("writing through null pointer (argument %d)",
arg_num);
/* Check for reading through a NULL pointer. */
&& i == 0
&& cur_param != 0
&& integer_zerop (cur_param))
- warning ("reading through null pointer (arg %d)",
+ warning ("reading through null pointer (argument %d)",
arg_num);
if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
&& i == 0
&& (TYPE_READONLY (cur_type)
|| (cur_param != 0
- && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
+ && (CONSTANT_CLASS_P (cur_param)
|| (DECL_P (cur_param)
&& TREE_READONLY (cur_param))))))
- warning ("writing into constant object (arg %d)", arg_num);
+ warning ("writing into constant object (argument %d)",
+ arg_num);
/* If there are extra type qualifiers beyond the first
indirection, then this makes the types technically
&& (TYPE_READONLY (cur_type)
|| TYPE_VOLATILE (cur_type)
|| TYPE_RESTRICT (cur_type)))
- warning ("extra type qualifiers in format argument (arg %d)",
+ warning ("extra type qualifiers in format argument "
+ "(argument %d)",
arg_num);
}
/* Check the type of the "real" argument, if there's a type we want. */
if (wanted_type == cur_type)
continue;
- /* If we want `void *', allow any pointer type.
+ /* If we want 'void *', allow any pointer type.
(Anything else would already have got a warning.)
With -pedantic, only allow pointers to void and to character
types. */
a second level of indirection. */
if (TREE_CODE (wanted_type) == INTEGER_TYPE
&& TREE_CODE (cur_type) == INTEGER_TYPE
- && (! pedantic || i == 0 || (i == 1 && char_type_flag))
+ && (!pedantic || i == 0 || (i == 1 && char_type_flag))
&& (TYPE_UNSIGNED (wanted_type)
? wanted_type == c_common_unsigned_type (cur_type)
: wanted_type == c_common_signed_type (cur_type)))
/* Likewise, "signed char", "unsigned char" and "char" are
equivalent but the above test won't consider them equivalent. */
if (wanted_type == char_type_node
- && (! pedantic || i < 2)
+ && (!pedantic || i < 2)
&& char_type_flag)
continue;
/* Now we have a type mismatch. */
static unsigned int
find_char_info_specifier_index (const format_char_info *fci, int c)
{
- unsigned int i = 0;
-
- while (fci->format_chars)
- {
- if (strchr (fci->format_chars, c))
- return i;
- i++; fci++;
- }
+ unsigned i;
+
+ for (i = 0; fci->format_chars; i++, fci++)
+ if (strchr (fci->format_chars, c))
+ return i;
/* We shouldn't be looking for a non-existent specifier. */
- abort ();
+ gcc_unreachable ();
}
/* Given a format_length_info array FLI, and a character C, this
static unsigned int
find_length_info_modifier_index (const format_length_info *fli, int c)
{
- unsigned int i = 0;
-
- while (fli->name)
- {
- if (strchr (fli->name, c))
- return i;
- i++; fli++;
- }
+ unsigned i;
+
+ for (i = 0; fli->name; i++, fli++)
+ if (strchr (fli->name, c))
+ return i;
/* We shouldn't be looking for a non-existent modifier. */
- abort ();
+ gcc_unreachable ();
}
/* Determine the type of HOST_WIDE_INT in the code being compiled for
init_dynamic_asm_fprintf_info (void)
{
static tree hwi;
-
+
if (!hwi)
{
format_length_info *new_asm_fprintf_length_specs;
length modifier to work, one must have issued: "typedef
HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code
prior to using that modifier. */
- if (!(hwi = maybe_get_identifier ("__gcc_host_wide_int__"))
- || !(hwi = DECL_ORIGINAL_TYPE (identifier_global_value (hwi))))
- abort ();
+ hwi = maybe_get_identifier ("__gcc_host_wide_int__");
+ gcc_assert (hwi);
+ hwi = DECL_ORIGINAL_TYPE (identifier_global_value (hwi));
+ gcc_assert (hwi);
/* Create a new (writable) copy of asm_fprintf_length_specs. */
new_asm_fprintf_length_specs = (format_length_info *)
else if (hwi == long_long_integer_type_node)
new_asm_fprintf_length_specs[i].index = FMT_LEN_ll;
else
- abort ();
+ gcc_unreachable ();
/* Assign the new data for use. */
dynamic_format_types[asm_fprintf_format_type].length_char_specs =
unsigned int i;
/* For the GCC-diagnostics custom format specifiers to work, one
- must have declared `tree' and/or `location_t' prior to using
+ must have declared 'tree' and/or 'location_t' prior to using
those attributes. If we haven't seen these declarations then
you shouldn't use the specifiers requiring these types.
However we don't force a hard ICE because we may see only one
if ((loc = maybe_get_identifier ("location_t")))
loc = TREE_TYPE (identifier_global_value (loc));
- /* We need to grab the underlying `union tree_node' so peek into
+ /* We need to grab the underlying 'union tree_node' so peek into
an extra type level. */
if ((t = maybe_get_identifier ("tree")))
t = TREE_TYPE (TREE_TYPE (identifier_global_value (t)));
/* Assign the new data for use. */
/* All the GCC diag formats use the same length specs. */
- if (! diag_ls)
+ if (!diag_ls)
dynamic_format_types[gcc_diag_format_type].length_char_specs =
dynamic_format_types[gcc_cdiag_format_type].length_char_specs =
dynamic_format_types[gcc_cxxdiag_format_type].length_char_specs =
else if (hwi == long_long_integer_type_node)
diag_ls[i].index = FMT_LEN_ll;
else
- abort ();
+ gcc_unreachable ();
}
/* Handle the __gcc_diag__ format specifics. */
- if (! diag_fci)
+ if (!diag_fci)
dynamic_format_types[gcc_diag_format_type].conversion_specs =
diag_fci = (format_char_info *)
xmemdup (gcc_diag_char_table,
- sizeof(gcc_diag_char_table),
- sizeof(gcc_diag_char_table));
+ sizeof (gcc_diag_char_table),
+ sizeof (gcc_diag_char_table));
if (loc)
{
i = find_char_info_specifier_index (diag_fci, 'H');
}
/* Handle the __gcc_cdiag__ format specifics. */
- if (! cdiag_fci)
+ if (!cdiag_fci)
dynamic_format_types[gcc_cdiag_format_type].conversion_specs =
cdiag_fci = (format_char_info *)
xmemdup (gcc_cdiag_char_table,
- sizeof(gcc_cdiag_char_table),
- sizeof(gcc_cdiag_char_table));
+ sizeof (gcc_cdiag_char_table),
+ sizeof (gcc_cdiag_char_table));
if (loc)
{
i = find_char_info_specifier_index (cdiag_fci, 'H');
}
/* Handle the __gcc_cxxdiag__ format specifics. */
- if (! cxxdiag_fci)
+ if (!cxxdiag_fci)
dynamic_format_types[gcc_cxxdiag_format_type].conversion_specs =
cxxdiag_fci = (format_char_info *)
xmemdup (gcc_cxxdiag_char_table,
- sizeof(gcc_cxxdiag_char_table),
- sizeof(gcc_cxxdiag_char_table));
+ sizeof (gcc_cxxdiag_char_table),
+ sizeof (gcc_cxxdiag_char_table));
if (loc)
{
i = find_char_info_specifier_index (cxxdiag_fci, 'H');
if (arg_num != info.first_arg_num)
{
if (!(flags & (int) ATTR_FLAG_BUILT_IN))
- error ("args to be formatted is not '...'");
+ error ("args to be formatted is not %<...%>");
*no_add_attrs = true;
return NULL_TREE;
}
/* If this is format __asm_fprintf__, we have to initialize
GCC's notion of HOST_WIDE_INT for checking %wd. */
if (info.format_type == asm_fprintf_format_type)
- init_dynamic_asm_fprintf_info();
+ init_dynamic_asm_fprintf_info ();
/* If this is one of the diagnostic attributes, then we have to
- initialize `location_t' and `tree' at runtime. */
+ initialize 'location_t' and 'tree' at runtime. */
else if (info.format_type == gcc_diag_format_type
|| info.format_type == gcc_cdiag_format_type
|| info.format_type == gcc_cxxdiag_format_type)
- init_dynamic_diag_info();
+ init_dynamic_diag_info ();
else
- abort();
+ gcc_unreachable ();
}
return NULL_TREE;