Commit 3f80e6ac by Kaveh R. Ghazi Committed by Kaveh Ghazi

Makefile.in (c-common.o): Depend on diagnostic.h.

	* Makefile.in (c-common.o): Depend on diagnostic.h.

	* c-common.c: Include diagnostic.h.
	(tfaff): Delete.
	(status_warning): New function.
	(check_format_info, maybe_read_dollar_number, check_format_types,
	finish_dollar_format_checking, check_function_format): Accept a
	`status' parameter.  All callers changed.

	* c-common.h (check_function_format): Accept a `status' parameter.

	* c-typeck.c: Update call to `check_function_format'.

cp:
	* cp-tree.h (check_function_format): Accept a `status' parameter.

	* call.c, typeck.c: Updates calls to `check_function_format'.

From-SVN: r36524
parent cfbd829c
2000-09-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (c-common.o): Depend on diagnostic.h.
* c-common.c: Include diagnostic.h.
(tfaff): Delete.
(status_warning): New function.
(check_format_info, maybe_read_dollar_number, check_format_types,
finish_dollar_format_checking, check_function_format): Accept a
`status' parameter. All callers changed.
* c-common.h (check_function_format): Accept a `status' parameter.
* c-typeck.c: Update call to `check_function_format'.
2000-09-18 Richard Henderson <rth@cygnus.com> 2000-09-18 Richard Henderson <rth@cygnus.com>
* c-decl.c (c_expand_body): Call mark_varargs before * c-decl.c (c_expand_body): Call mark_varargs before
......
...@@ -1162,7 +1162,7 @@ s-under: $(GCC_PASSES) ...@@ -1162,7 +1162,7 @@ s-under: $(GCC_PASSES)
c-common.o : c-common.c $(CONFIG_H) system.h $(TREE_H) \ c-common.o : c-common.c $(CONFIG_H) system.h $(TREE_H) \
$(C_COMMON_H) flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \ $(C_COMMON_H) flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
$(EXPR_H) $(EXPR_H) diagnostic.h
c-semantics.o : c-semantics.c $(CONFIG_H) system.h $(TREE_H) $(C_TREE_H) \ c-semantics.o : c-semantics.c $(CONFIG_H) system.h $(TREE_H) $(C_TREE_H) \
c-lex.h flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \ c-lex.h flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
......
...@@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */
#include "c-common.h" #include "c-common.h"
#include "tm_p.h" #include "tm_p.h"
#include "intl.h" #include "intl.h"
#include "diagnostic.h"
#if USE_CPPLIB #if USE_CPPLIB
#include "cpplib.h" #include "cpplib.h"
...@@ -187,7 +188,6 @@ typedef struct ...@@ -187,7 +188,6 @@ typedef struct
int needs_warning; int needs_warning;
tree if_stmt; tree if_stmt;
} if_elt; } if_elt;
static void tfaff PARAMS ((void));
static if_elt *if_stack; static if_elt *if_stack;
...@@ -1535,14 +1535,16 @@ typedef struct international_format_info ...@@ -1535,14 +1535,16 @@ typedef struct international_format_info
static international_format_info *international_format_list = NULL; static international_format_info *international_format_list = NULL;
static void check_format_info PARAMS ((function_format_info *, tree)); static void check_format_info PARAMS ((int *, function_format_info *, tree));
static void status_warning PARAMS ((int *, const char *, ...))
ATTRIBUTE_PRINTF_2;
static void init_dollar_format_checking PARAMS ((int, tree)); static void init_dollar_format_checking PARAMS ((int, tree));
static int maybe_read_dollar_number PARAMS ((const char **, int, static int maybe_read_dollar_number PARAMS ((int *, const char **, int,
tree, tree *)); tree, tree *));
static void finish_dollar_format_checking PARAMS ((void)); static void finish_dollar_format_checking PARAMS ((int *));
static void check_format_types PARAMS ((format_wanted_type *)); static void check_format_types PARAMS ((int *, format_wanted_type *));
/* Initialize the table of functions to perform format checking on. /* Initialize the table of functions to perform format checking on.
The ISO C functions are always checked (whether <stdio.h> is The ISO C functions are always checked (whether <stdio.h> is
...@@ -1687,12 +1689,6 @@ record_international_format (name, assembler_name, format_num) ...@@ -1687,12 +1689,6 @@ record_international_format (name, assembler_name, format_num)
info->format_num = format_num; info->format_num = format_num;
} }
static void
tfaff ()
{
warning ("too few arguments for format");
}
/* Check the argument list of a call to printf, scanf, etc. /* Check the argument list of a call to printf, scanf, etc.
NAME is the function identifier. NAME is the function identifier.
ASSEMBLER_NAME is the function's assembler identifier. ASSEMBLER_NAME is the function's assembler identifier.
...@@ -1700,7 +1696,8 @@ tfaff () ...@@ -1700,7 +1696,8 @@ tfaff ()
PARAMS is the list of argument values. */ PARAMS is the list of argument values. */
void void
check_function_format (name, assembler_name, params) check_function_format (status, name, assembler_name, params)
int *status;
tree name; tree name;
tree assembler_name; tree assembler_name;
tree params; tree params;
...@@ -1715,12 +1712,46 @@ check_function_format (name, assembler_name, params) ...@@ -1715,12 +1712,46 @@ check_function_format (name, assembler_name, params)
: (info->name == name)) : (info->name == name))
{ {
/* Yup; check it. */ /* Yup; check it. */
check_format_info (info, params); check_format_info (status, info, params);
break; break;
} }
} }
} }
/* This function replaces `warning' inside the printf format checking
functions. If the `status' parameter is non-NULL, then it is
dereferenced and set to 1 whenever a warning is caught. Otherwise
it warns as usual by replicating the innards of the warning
function from diagnostic.c. */
static void
status_warning VPARAMS ((int *status, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
int *status;
const char *msgid;
#endif
va_list ap;
diagnostic_context dc;
if (status)
*status = 1;
else
{
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
status = va_arg (ap, int *);
msgid = va_arg (ap, const char *);
#endif
/* This duplicates the warning function behavior. */
set_diagnostic_context
(&dc, msgid, &ap, input_filename, lineno, /* warn = */ 1);
report_diagnostic (&dc);
va_end (ap);
}
}
/* Variables used by the checking of $ operand number formats. */ /* Variables used by the checking of $ operand number formats. */
static char *dollar_arguments_used = NULL; static char *dollar_arguments_used = NULL;
...@@ -1775,7 +1806,8 @@ init_dollar_format_checking (first_arg_num, params) ...@@ -1775,7 +1806,8 @@ init_dollar_format_checking (first_arg_num, params)
a $ format is found, *FORMAT is updated to point just after it. */ a $ format is found, *FORMAT is updated to point just after it. */
static int static int
maybe_read_dollar_number (format, dollar_needed, params, param_ptr) maybe_read_dollar_number (status, format, dollar_needed, params, param_ptr)
int *status;
const char **format; const char **format;
int dollar_needed; int dollar_needed;
tree params; tree params;
...@@ -1788,7 +1820,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) ...@@ -1788,7 +1820,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr)
{ {
if (dollar_needed) if (dollar_needed)
{ {
warning ("missing $ operand number in format"); status_warning (status, "missing $ operand number in format");
return -1; return -1;
} }
else else
...@@ -1809,7 +1841,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) ...@@ -1809,7 +1841,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr)
{ {
if (dollar_needed) if (dollar_needed)
{ {
warning ("missing $ operand number in format"); status_warning (status, "missing $ operand number in format");
return -1; return -1;
} }
else else
...@@ -1818,13 +1850,13 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) ...@@ -1818,13 +1850,13 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr)
*format = fcp + 1; *format = fcp + 1;
if (pedantic && !dollar_format_warned) if (pedantic && !dollar_format_warned)
{ {
warning ("ISO C does not support %%n$ operand number formats"); status_warning (status, "ISO C does not support %%n$ operand number formats");
dollar_format_warned = 1; dollar_format_warned = 1;
} }
if (overflow_flag || argnum == 0 if (overflow_flag || argnum == 0
|| (dollar_first_arg_num && argnum > dollar_arguments_count)) || (dollar_first_arg_num && argnum > dollar_arguments_count))
{ {
warning ("operand number out of range in format"); status_warning (status, "operand number out of range in format");
return -1; return -1;
} }
if (argnum > dollar_max_arg_used) if (argnum > dollar_max_arg_used)
...@@ -1870,17 +1902,18 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) ...@@ -1870,17 +1902,18 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr)
here. */ here. */
static void static void
finish_dollar_format_checking () finish_dollar_format_checking (status)
int *status;
{ {
int i; int i;
for (i = 0; i < dollar_max_arg_used; i++) for (i = 0; i < dollar_max_arg_used; i++)
{ {
if (!dollar_arguments_used[i]) if (!dollar_arguments_used[i])
warning ("format argument %d unused before used argument %d in $-style format", status_warning (status, "format argument %d unused before used argument %d in $-style format",
i + 1, dollar_max_arg_used); i + 1, dollar_max_arg_used);
} }
if (dollar_first_arg_num && dollar_max_arg_used < dollar_arguments_count) if (dollar_first_arg_num && dollar_max_arg_used < dollar_arguments_count)
warning ("unused arguments in $-style format"); status_warning (status, "unused arguments in $-style format");
} }
...@@ -1889,7 +1922,8 @@ finish_dollar_format_checking () ...@@ -1889,7 +1922,8 @@ finish_dollar_format_checking ()
PARAMS is the list of argument values. */ PARAMS is the list of argument values. */
static void static void
check_format_info (info, params) check_format_info (status, info, params)
int *status;
function_format_info *info; function_format_info *info;
tree params; tree params;
{ {
...@@ -1976,7 +2010,7 @@ check_format_info (info, params) ...@@ -1976,7 +2010,7 @@ check_format_info (info, params)
if (integer_zerop (format_tree)) if (integer_zerop (format_tree))
{ {
warning ("null format string"); status_warning (status, "null format string");
return; return;
} }
if (TREE_CODE (format_tree) != ADDR_EXPR) if (TREE_CODE (format_tree) != ADDR_EXPR)
...@@ -1987,7 +2021,7 @@ check_format_info (info, params) ...@@ -1987,7 +2021,7 @@ check_format_info (info, params)
string. These functions typically are declared with string. These functions typically are declared with
first_arg_num == 0, so avoid warning in those cases. */ first_arg_num == 0, so avoid warning in those cases. */
if (info->first_arg_num != 0 && warn_format > 1) if (info->first_arg_num != 0 && warn_format > 1)
warning ("format not a string literal, argument types not checked"); status_warning (status, "format not a string literal, argument types not checked");
return; return;
} }
format_tree = TREE_OPERAND (format_tree, 0); format_tree = TREE_OPERAND (format_tree, 0);
...@@ -1999,16 +2033,16 @@ check_format_info (info, params) ...@@ -1999,16 +2033,16 @@ check_format_info (info, params)
string. These functions typically are declared with string. These functions typically are declared with
first_arg_num == 0, so avoid warning in those cases. */ first_arg_num == 0, so avoid warning in those cases. */
if (info->first_arg_num != 0 && warn_format > 1) if (info->first_arg_num != 0 && warn_format > 1)
warning ("format not a string literal, argument types not checked"); status_warning (status, "format not a string literal, argument types not checked");
return; return;
} }
format_chars = TREE_STRING_POINTER (format_tree); format_chars = TREE_STRING_POINTER (format_tree);
format_length = TREE_STRING_LENGTH (format_tree); format_length = TREE_STRING_LENGTH (format_tree);
if (format_length <= 1) if (format_length <= 1)
warning ("zero-length format string"); status_warning (status, "zero-length format string");
if (format_chars[--format_length] != 0) if (format_chars[--format_length] != 0)
{ {
warning ("unterminated format string"); status_warning (status, "unterminated format string");
return; return;
} }
/* Skip to first argument to check. */ /* Skip to first argument to check. */
...@@ -2031,19 +2065,19 @@ check_format_info (info, params) ...@@ -2031,19 +2065,19 @@ check_format_info (info, params)
if (*format_chars == 0) if (*format_chars == 0)
{ {
if (format_chars - TREE_STRING_POINTER (format_tree) != format_length) if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
warning ("embedded `\\0' in format"); status_warning (status, "embedded `\\0' in format");
if (info->first_arg_num != 0 && params != 0 if (info->first_arg_num != 0 && params != 0
&& has_operand_number <= 0) && has_operand_number <= 0)
warning ("too many arguments for format"); status_warning (status, "too many arguments for format");
if (has_operand_number > 0) if (has_operand_number > 0)
finish_dollar_format_checking (); finish_dollar_format_checking (status);
return; return;
} }
if (*format_chars++ != '%') if (*format_chars++ != '%')
continue; continue;
if (*format_chars == 0) if (*format_chars == 0)
{ {
warning ("spurious trailing `%%' in format"); status_warning (status, "spurious trailing `%%' in format");
continue; continue;
} }
if (*format_chars == '%') if (*format_chars == '%')
...@@ -2064,7 +2098,7 @@ check_format_info (info, params) ...@@ -2064,7 +2098,7 @@ check_format_info (info, params)
else if (has_operand_number != 0) else if (has_operand_number != 0)
{ {
int opnum; int opnum;
opnum = maybe_read_dollar_number (&format_chars, opnum = maybe_read_dollar_number (status, &format_chars,
has_operand_number == 1, has_operand_number == 1,
first_fillin_param, first_fillin_param,
&main_arg_params); &main_arg_params);
...@@ -2086,18 +2120,18 @@ check_format_info (info, params) ...@@ -2086,18 +2120,18 @@ check_format_info (info, params)
++format_chars; ++format_chars;
} }
if (wide && !non_zero_width_char) if (wide && !non_zero_width_char)
warning ("zero width in scanf format"); status_warning (status, "zero width in scanf format");
} }
else if (info->format_type == strftime_format_type) else if (info->format_type == strftime_format_type)
{ {
while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0) while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0)
{ {
if (pedantic) if (pedantic)
warning ("ISO C does not support the strftime `%c' flag", status_warning (status, "ISO C does not support the strftime `%c' flag",
*format_chars); *format_chars);
if (index (flag_chars, *format_chars) != 0) if (index (flag_chars, *format_chars) != 0)
{ {
warning ("repeated `%c' flag in format", status_warning (status, "repeated `%c' flag in format",
*format_chars); *format_chars);
++format_chars; ++format_chars;
} }
...@@ -2114,7 +2148,7 @@ check_format_info (info, params) ...@@ -2114,7 +2148,7 @@ check_format_info (info, params)
++format_chars; ++format_chars;
} }
if (wide && pedantic) if (wide && pedantic)
warning ("ISO C does not support strftime format width"); status_warning (status, "ISO C does not support strftime format width");
if (*format_chars == 'E' || *format_chars == 'O') if (*format_chars == 'E' || *format_chars == 'O')
{ {
i = strlen (flag_chars); i = strlen (flag_chars);
...@@ -2122,7 +2156,7 @@ check_format_info (info, params) ...@@ -2122,7 +2156,7 @@ check_format_info (info, params)
flag_chars[i] = 0; flag_chars[i] = 0;
if (*format_chars == 'E' || *format_chars == 'O') if (*format_chars == 'E' || *format_chars == 'O')
{ {
warning ("multiple E/O modifiers in format"); status_warning (status, "multiple E/O modifiers in format");
while (*format_chars == 'E' || *format_chars == 'O') while (*format_chars == 'E' || *format_chars == 'O')
++format_chars; ++format_chars;
} }
...@@ -2133,7 +2167,7 @@ check_format_info (info, params) ...@@ -2133,7 +2167,7 @@ check_format_info (info, params)
if (has_operand_number != 0) if (has_operand_number != 0)
{ {
int opnum; int opnum;
opnum = maybe_read_dollar_number (&format_chars, opnum = maybe_read_dollar_number (status, &format_chars,
0, first_fillin_param, 0, first_fillin_param,
&main_arg_params); &main_arg_params);
if (opnum == -1) if (opnum == -1)
...@@ -2148,7 +2182,7 @@ check_format_info (info, params) ...@@ -2148,7 +2182,7 @@ check_format_info (info, params)
while (*format_chars != 0 && index (" +#0-'I", *format_chars) != 0) while (*format_chars != 0 && index (" +#0-'I", *format_chars) != 0)
{ {
if (index (flag_chars, *format_chars) != 0) if (index (flag_chars, *format_chars) != 0)
warning ("repeated `%c' flag in format", *format_chars++); status_warning (status, "repeated `%c' flag in format", *format_chars++);
else else
{ {
i = strlen (flag_chars); i = strlen (flag_chars);
...@@ -2160,16 +2194,16 @@ check_format_info (info, params) ...@@ -2160,16 +2194,16 @@ check_format_info (info, params)
the space flag will be ignored." */ the space flag will be ignored." */
if (index (flag_chars, ' ') != 0 if (index (flag_chars, ' ') != 0
&& index (flag_chars, '+') != 0) && index (flag_chars, '+') != 0)
warning ("use of both ` ' and `+' flags in format"); status_warning (status, "use of both ` ' and `+' flags in format");
/* "If the 0 and - flags both appear, /* "If the 0 and - flags both appear,
the 0 flag will be ignored." */ the 0 flag will be ignored." */
if (index (flag_chars, '0') != 0 if (index (flag_chars, '0') != 0
&& index (flag_chars, '-') != 0) && index (flag_chars, '-') != 0)
warning ("use of both `0' and `-' flags in format"); status_warning (status, "use of both `0' and `-' flags in format");
if (index (flag_chars, '\'') && pedantic) if (index (flag_chars, '\'') && pedantic)
warning ("ISO C does not support the `'' format flag"); status_warning (status, "ISO C does not support the `'' format flag");
if (index (flag_chars, 'I') && pedantic) if (index (flag_chars, 'I') && pedantic)
warning ("ISO C does not support the `I' format flag"); status_warning (status, "ISO C does not support the `I' format flag");
if (*format_chars == '*') if (*format_chars == '*')
{ {
wide = TRUE; wide = TRUE;
...@@ -2178,13 +2212,13 @@ check_format_info (info, params) ...@@ -2178,13 +2212,13 @@ check_format_info (info, params)
++format_chars; ++format_chars;
if (params == 0) if (params == 0)
{ {
tfaff (); status_warning (status, "too few arguments for format");
return; return;
} }
if (has_operand_number != 0) if (has_operand_number != 0)
{ {
int opnum; int opnum;
opnum = maybe_read_dollar_number (&format_chars, opnum = maybe_read_dollar_number (status, &format_chars,
has_operand_number == 1, has_operand_number == 1,
first_fillin_param, first_fillin_param,
&params); &params);
...@@ -2242,7 +2276,7 @@ check_format_info (info, params) ...@@ -2242,7 +2276,7 @@ check_format_info (info, params)
if (has_operand_number != 0) if (has_operand_number != 0)
{ {
int opnum; int opnum;
opnum = maybe_read_dollar_number (&format_chars, opnum = maybe_read_dollar_number (status, &format_chars,
has_operand_number == 1, has_operand_number == 1,
first_fillin_param, first_fillin_param,
&params); &params);
...@@ -2260,7 +2294,7 @@ check_format_info (info, params) ...@@ -2260,7 +2294,7 @@ check_format_info (info, params)
{ {
if (params == 0) if (params == 0)
{ {
tfaff (); status_warning (status, "too few arguments for format");
return; return;
} }
cur_param = TREE_VALUE (params); cur_param = TREE_VALUE (params);
...@@ -2327,11 +2361,11 @@ check_format_info (info, params) ...@@ -2327,11 +2361,11 @@ check_format_info (info, params)
{ {
/* Warn if the length modifier is non-standard. */ /* Warn if the length modifier is non-standard. */
if (length_chars_std == STD_EXT) if (length_chars_std == STD_EXT)
warning ("ISO C does not support the `%s' %s length modifier", status_warning (status, "ISO C does not support the `%s' %s length modifier",
length_chars, fki->name); length_chars, fki->name);
else if ((length_chars_std == STD_C99 && !flag_isoc99) else if ((length_chars_std == STD_C99 && !flag_isoc99)
|| (length_chars_std == STD_C94 && !flag_isoc94)) || (length_chars_std == STD_C94 && !flag_isoc94))
warning ("ISO C89 does not support the `%s' %s length modifier", status_warning (status, "ISO C89 does not support the `%s' %s length modifier",
length_chars, fki->name); length_chars, fki->name);
} }
if (*format_chars == 'a' && info->format_type == scanf_format_type if (*format_chars == 'a' && info->format_type == scanf_format_type
...@@ -2346,13 +2380,13 @@ check_format_info (info, params) ...@@ -2346,13 +2380,13 @@ check_format_info (info, params)
} }
} }
if (suppressed && length_chars_val != FMT_LEN_none) if (suppressed && length_chars_val != FMT_LEN_none)
warning ("use of `*' and `%s' together in format", length_chars); status_warning (status, "use of `*' and `%s' together in format", length_chars);
} }
format_char = *format_chars; format_char = *format_chars;
if (format_char == 0 if (format_char == 0
|| (info->format_type != strftime_format_type && format_char == '%')) || (info->format_type != strftime_format_type && format_char == '%'))
{ {
warning ("conversion lacks type at end of format"); status_warning (status, "conversion lacks type at end of format");
continue; continue;
} }
format_chars++; format_chars++;
...@@ -2363,51 +2397,51 @@ check_format_info (info, params) ...@@ -2363,51 +2397,51 @@ check_format_info (info, params)
if (fci->format_chars == 0) if (fci->format_chars == 0)
{ {
if (ISGRAPH(format_char)) if (ISGRAPH(format_char))
warning ("unknown conversion type character `%c' in format", status_warning (status, "unknown conversion type character `%c' in format",
format_char); format_char);
else else
warning ("unknown conversion type character 0x%x in format", status_warning (status, "unknown conversion type character 0x%x in format",
format_char); format_char);
continue; continue;
} }
if (pedantic) if (pedantic)
{ {
if (fci->std == STD_EXT) if (fci->std == STD_EXT)
warning ("ISO C does not support the `%%%c' %s format", status_warning (status, "ISO C does not support the `%%%c' %s format",
format_char, fki->name); format_char, fki->name);
else if ((fci->std == STD_C99 && !flag_isoc99) else if ((fci->std == STD_C99 && !flag_isoc99)
|| (fci->std == STD_C94 && !flag_isoc94)) || (fci->std == STD_C94 && !flag_isoc94))
warning ("ISO C89 does not support the `%%%c' %s format", status_warning (status, "ISO C89 does not support the `%%%c' %s format",
format_char, fki->name); format_char, fki->name);
if (index (flag_chars, 'O') != 0) if (index (flag_chars, 'O') != 0)
{ {
if (index (fci->flag_chars, 'o') != 0) if (index (fci->flag_chars, 'o') != 0)
warning ("ISO C does not support `%%O%c'", format_char); status_warning (status, "ISO C does not support `%%O%c'", format_char);
else if (!flag_isoc99 && index (fci->flag_chars, 'O') != 0) else if (!flag_isoc99 && index (fci->flag_chars, 'O') != 0)
warning ("ISO C89 does not support `%%O%c'", format_char); status_warning (status, "ISO C89 does not support `%%O%c'", format_char);
} }
if (!flag_isoc99 && index (flag_chars, 'E')) if (!flag_isoc99 && index (flag_chars, 'E'))
warning ("ISO C89 does not support `%%E%c'", format_char); status_warning (status, "ISO C89 does not support `%%E%c'", format_char);
} }
if (wide && index (fci->flag_chars, 'w') == 0) if (wide && index (fci->flag_chars, 'w') == 0)
warning ("width used with `%c' format", format_char); status_warning (status, "width used with `%c' format", format_char);
if (index (fci->flag_chars, '3') != 0 if (index (fci->flag_chars, '3') != 0
|| (format_char == 'y' && index (flag_chars, 'E'))) || (format_char == 'y' && index (flag_chars, 'E')))
warning ("`%%%c' yields only last 2 digits of year in some locales", status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
format_char); format_char);
else if (index (fci->flag_chars, '2') != 0) else if (index (fci->flag_chars, '2') != 0)
warning ("`%%%c' yields only last 2 digits of year", format_char); status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);
if (precise && index (fci->flag_chars, 'p') == 0) if (precise && index (fci->flag_chars, 'p') == 0)
warning ("precision used with `%c' format", format_char); status_warning (status, "precision used with `%c' format", format_char);
if (aflag && index (fci->flag_chars, 'a') == 0) if (aflag && index (fci->flag_chars, 'a') == 0)
{ {
warning ("`a' flag used with `%c' format", format_char); status_warning (status, "`a' flag used with `%c' format", format_char);
/* To simplify the following code. */ /* To simplify the following code. */
aflag = 0; aflag = 0;
} }
/* The a flag is a GNU extension. */ /* The a flag is a GNU extension. */
else if (pedantic && aflag) else if (pedantic && aflag)
warning ("ISO C does not support the `a' flag"); status_warning (status, "ISO C does not support the `a' flag");
if (info->format_type == scanf_format_type && format_char == '[') if (info->format_type == scanf_format_type && format_char == '[')
{ {
/* Skip over scan set, in case it happens to have '%' in it. */ /* Skip over scan set, in case it happens to have '%' in it. */
...@@ -2421,18 +2455,18 @@ check_format_info (info, params) ...@@ -2421,18 +2455,18 @@ check_format_info (info, params)
++format_chars; ++format_chars;
if (*format_chars != ']') if (*format_chars != ']')
/* The end of the format string was reached. */ /* The end of the format string was reached. */
warning ("no closing `]' for `%%[' format"); status_warning (status, "no closing `]' for `%%[' format");
} }
if (suppressed) if (suppressed)
{ {
if (index (fci->flag_chars, '*') == 0) if (index (fci->flag_chars, '*') == 0)
warning ("suppression of `%c' conversion in format", format_char); status_warning (status, "suppression of `%c' conversion in format", format_char);
continue; continue;
} }
for (i = 0; flag_chars[i] != 0; ++i) for (i = 0; flag_chars[i] != 0; ++i)
{ {
if (index (fci->flag_chars, flag_chars[i]) == 0) if (index (fci->flag_chars, flag_chars[i]) == 0)
warning ("flag `%c' used with type `%c'", status_warning (status, "flag `%c' used with type `%c'",
flag_chars[i], format_char); flag_chars[i], format_char);
} }
if (info->format_type == strftime_format_type) if (info->format_type == strftime_format_type)
...@@ -2441,7 +2475,7 @@ check_format_info (info, params) ...@@ -2441,7 +2475,7 @@ check_format_info (info, params)
&& (format_char == 'd' || format_char == 'i' && (format_char == 'd' || format_char == 'i'
|| format_char == 'o' || format_char == 'u' || format_char == 'o' || format_char == 'u'
|| format_char == 'x' || format_char == 'X')) || format_char == 'x' || format_char == 'X'))
warning ("`0' flag ignored with precision specifier and `%c' format", status_warning (status, "`0' flag ignored with precision specifier and `%c' format",
format_char); format_char);
wanted_type = (fci->types[length_chars_val].type wanted_type = (fci->types[length_chars_val].type
? *fci->types[length_chars_val].type : 0); ? *fci->types[length_chars_val].type : 0);
...@@ -2449,14 +2483,14 @@ check_format_info (info, params) ...@@ -2449,14 +2483,14 @@ check_format_info (info, params)
wanted_type_std = fci->types[length_chars_val].std; wanted_type_std = fci->types[length_chars_val].std;
if (wanted_type == 0) if (wanted_type == 0)
{ {
warning ("use of `%s' length modifier with `%c' type character", status_warning (status, "use of `%s' length modifier with `%c' type character",
length_chars, format_char); length_chars, format_char);
/* Heuristic: skip one argument when an invalid length/type /* Heuristic: skip one argument when an invalid length/type
combination is encountered. */ combination is encountered. */
arg_num++; arg_num++;
if (params == 0) if (params == 0)
{ {
tfaff (); status_warning (status, "too few arguments for format");
return; return;
} }
params = TREE_CHAIN (params); params = TREE_CHAIN (params);
...@@ -2470,11 +2504,11 @@ check_format_info (info, params) ...@@ -2470,11 +2504,11 @@ check_format_info (info, params)
&& wanted_type_std > fci->std) && wanted_type_std > fci->std)
{ {
if (wanted_type_std == STD_EXT) if (wanted_type_std == STD_EXT)
warning ("ISO C does not support the `%%%s%c' %s format", status_warning (status, "ISO C does not support the `%%%s%c' %s format",
length_chars, format_char, fki->name); length_chars, format_char, fki->name);
else if ((wanted_type_std == STD_C99 && !flag_isoc99) else if ((wanted_type_std == STD_C99 && !flag_isoc99)
|| (wanted_type_std == STD_C94 && !flag_isoc94)) || (wanted_type_std == STD_C94 && !flag_isoc94))
warning ("ISO C89 does not support the `%%%s%c' %s format", status_warning (status, "ISO C89 does not support the `%%%s%c' %s format",
length_chars, format_char, fki->name); length_chars, format_char, fki->name);
} }
...@@ -2484,7 +2518,7 @@ check_format_info (info, params) ...@@ -2484,7 +2518,7 @@ check_format_info (info, params)
if (fci->pointer_count == 0 && wanted_type == void_type_node) if (fci->pointer_count == 0 && wanted_type == void_type_node)
{ {
if (main_arg_num != 0) if (main_arg_num != 0)
warning ("operand number specified for format taking no argument"); status_warning (status, "operand number specified for format taking no argument");
} }
else else
{ {
...@@ -2498,14 +2532,14 @@ check_format_info (info, params) ...@@ -2498,14 +2532,14 @@ check_format_info (info, params)
++arg_num; ++arg_num;
if (has_operand_number > 0) if (has_operand_number > 0)
{ {
warning ("missing $ operand number in format"); status_warning (status, "missing $ operand number in format");
return; return;
} }
else else
has_operand_number = 0; has_operand_number = 0;
if (params == 0) if (params == 0)
{ {
tfaff (); status_warning (status, "too few arguments for format");
return; return;
} }
} }
...@@ -2532,7 +2566,7 @@ check_format_info (info, params) ...@@ -2532,7 +2566,7 @@ check_format_info (info, params)
} }
if (first_wanted_type != 0) if (first_wanted_type != 0)
check_format_types (first_wanted_type); check_format_types (status, first_wanted_type);
} }
} }
...@@ -2541,7 +2575,8 @@ check_format_info (info, params) ...@@ -2541,7 +2575,8 @@ check_format_info (info, params)
/* Check the argument types from a single format conversion (possibly /* Check the argument types from a single format conversion (possibly
including width and precision arguments). */ including width and precision arguments). */
static void static void
check_format_types (types) check_format_types (status, types)
int *status;
format_wanted_type *types; format_wanted_type *types;
{ {
for (; types != 0; types = types->next) for (; types != 0; types = types->next)
...@@ -2596,7 +2631,7 @@ check_format_types (types) ...@@ -2596,7 +2631,7 @@ check_format_types (types)
&& (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c' && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
|| (DECL_P (cur_param) || (DECL_P (cur_param)
&& TREE_READONLY (cur_param)))))) && TREE_READONLY (cur_param))))))
warning ("writing into constant object (arg %d)", arg_num); status_warning (status, "writing into constant object (arg %d)", arg_num);
/* If there are extra type qualifiers beyond the first /* If there are extra type qualifiers beyond the first
indirection, then this makes the types technically indirection, then this makes the types technically
...@@ -2606,16 +2641,16 @@ check_format_types (types) ...@@ -2606,16 +2641,16 @@ check_format_types (types)
&& (TYPE_READONLY (cur_type) && (TYPE_READONLY (cur_type)
|| TYPE_VOLATILE (cur_type) || TYPE_VOLATILE (cur_type)
|| TYPE_RESTRICT (cur_type))) || TYPE_RESTRICT (cur_type)))
warning ("extra type qualifiers in format argument (arg %d)", status_warning (status, "extra type qualifiers in format argument (arg %d)",
arg_num); arg_num);
} }
else else
{ {
if (types->pointer_count == 1) if (types->pointer_count == 1)
warning ("format argument is not a pointer (arg %d)", arg_num); status_warning (status, "format argument is not a pointer (arg %d)", arg_num);
else else
warning ("format argument is not a pointer to a pointer (arg %d)", arg_num); status_warning (status, "format argument is not a pointer to a pointer (arg %d)", arg_num);
break; break;
} }
} }
...@@ -2709,10 +2744,10 @@ check_format_types (types) ...@@ -2709,10 +2744,10 @@ check_format_types (types)
&& strcmp (types->wanted_type_name, that) != 0) && strcmp (types->wanted_type_name, that) != 0)
this = types->wanted_type_name; this = types->wanted_type_name;
if (types->name != 0) if (types->name != 0)
warning ("%s is not type %s (arg %d)", types->name, this, status_warning (status, "%s is not type %s (arg %d)", types->name, this,
arg_num); arg_num);
else else
warning ("%s format, %s arg (arg %d)", this, that, arg_num); status_warning (status, "%s format, %s arg (arg %d)", this, that, arg_num);
} }
} }
} }
......
...@@ -396,7 +396,7 @@ extern tree (*make_fname_decl) PARAMS ((tree, const char *, int ...@@ -396,7 +396,7 @@ extern tree (*make_fname_decl) PARAMS ((tree, const char *, int
extern void declare_function_name PARAMS ((void)); extern void declare_function_name PARAMS ((void));
extern void decl_attributes PARAMS ((tree, tree, tree)); extern void decl_attributes PARAMS ((tree, tree, tree));
extern void init_function_format_info PARAMS ((void)); extern void init_function_format_info PARAMS ((void));
extern void check_function_format PARAMS ((tree, tree, tree)); extern void check_function_format PARAMS ((int *, tree, tree, tree));
extern void c_apply_type_quals_to_decl PARAMS ((int, tree)); extern void c_apply_type_quals_to_decl PARAMS ((int, tree));
/* Print an error message for invalid operands to arith operation CODE. /* Print an error message for invalid operands to arith operation CODE.
NOP_EXPR is used as a special case (see truthvalue_conversion). */ NOP_EXPR is used as a special case (see truthvalue_conversion). */
......
...@@ -1533,7 +1533,7 @@ build_function_call (function, params) ...@@ -1533,7 +1533,7 @@ build_function_call (function, params)
/* Check for errors in format strings. */ /* Check for errors in format strings. */
if (warn_format && (name || assembler_name)) if (warn_format && (name || assembler_name))
check_function_format (name, assembler_name, coerced_params); check_function_format (NULL, name, assembler_name, coerced_params);
/* Recognize certain built-in functions so we can make tree-codes /* Recognize certain built-in functions so we can make tree-codes
other than CALL_EXPR. We do this when it enables fold-const.c other than CALL_EXPR. We do this when it enables fold-const.c
......
2000-09-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* cp-tree.h (check_function_format): Accept a `status' parameter.
* call.c, typeck.c: Updates calls to `check_function_format'.
2000-09-17 Geoffrey Keating <geoffk@cygnus.com> 2000-09-17 Geoffrey Keating <geoffk@cygnus.com>
* decl2.c (handle_class_head): Always push some scope even * decl2.c (handle_class_head): Always push some scope even
......
...@@ -4050,7 +4050,7 @@ build_over_call (cand, args, flags) ...@@ -4050,7 +4050,7 @@ build_over_call (cand, args, flags)
converted_args = nreverse (converted_args); converted_args = nreverse (converted_args);
if (warn_format && (DECL_NAME (fn) || DECL_ASSEMBLER_NAME (fn))) if (warn_format && (DECL_NAME (fn) || DECL_ASSEMBLER_NAME (fn)))
check_function_format (DECL_NAME (fn), DECL_ASSEMBLER_NAME (fn), check_function_format (NULL, DECL_NAME (fn), DECL_ASSEMBLER_NAME (fn),
converted_args); converted_args);
/* Avoid actually calling copy constructors and copy assignment operators, /* Avoid actually calling copy constructors and copy assignment operators,
......
...@@ -3186,7 +3186,7 @@ extern void declare_function_name PARAMS ((void)); ...@@ -3186,7 +3186,7 @@ extern void declare_function_name PARAMS ((void));
extern void decl_attributes PARAMS ((tree, tree, tree)); extern void decl_attributes PARAMS ((tree, tree, tree));
extern void init_function_format_info PARAMS ((void)); extern void init_function_format_info PARAMS ((void));
extern void record_function_format PARAMS ((tree, tree, int, int, int)); extern void record_function_format PARAMS ((tree, tree, int, int, int));
extern void check_function_format PARAMS ((tree, tree, tree)); extern void check_function_format PARAMS ((int *, tree, tree, tree));
/* Print an error message for invalid operands to arith operation CODE. /* Print an error message for invalid operands to arith operation CODE.
NOP_EXPR is used as a special case (see truthvalue_conversion). */ NOP_EXPR is used as a special case (see truthvalue_conversion). */
extern void binary_op_error PARAMS ((enum tree_code)); extern void binary_op_error PARAMS ((enum tree_code));
......
...@@ -3026,7 +3026,7 @@ build_function_call_real (function, params, require_complete, flags) ...@@ -3026,7 +3026,7 @@ build_function_call_real (function, params, require_complete, flags)
/* Check for errors in format strings. */ /* Check for errors in format strings. */
if (warn_format && (name || assembler_name)) if (warn_format && (name || assembler_name))
check_function_format (name, assembler_name, coerced_params); check_function_format (NULL, name, assembler_name, coerced_params);
/* Recognize certain built-in functions so we can make tree-codes /* Recognize certain built-in functions so we can make tree-codes
other than CALL_EXPR. We do this when it enables fold-const.c other than CALL_EXPR. We do this when it enables fold-const.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment