diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-09-19 03:26:11 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-09-19 03:26:11 +0000 |
commit | e0bc5413a640e88da968397f6292c21e39e0d44a (patch) | |
tree | bea5d273a641ed7dce8b14e7877a7f9c20e1ab85 /gcc/c-common.c | |
parent | 5e0e5c5e16ea6956d90bef7f09da2e31c9147440 (diff) | |
download | gcc-e0bc5413a640e88da968397f6292c21e39e0d44a.tar.gz |
* 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'.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@36524 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 201 |
1 files changed, 118 insertions, 83 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 6a1e687f42c..5ede422d311 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */ #include "c-common.h" #include "tm_p.h" #include "intl.h" +#include "diagnostic.h" #if USE_CPPLIB #include "cpplib.h" @@ -187,7 +188,6 @@ typedef struct int needs_warning; tree if_stmt; } if_elt; -static void tfaff PARAMS ((void)); static if_elt *if_stack; @@ -1535,14 +1535,16 @@ typedef struct international_format_info 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 int maybe_read_dollar_number PARAMS ((const char **, int, +static int maybe_read_dollar_number PARAMS ((int *, const char **, int, 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. The ISO C functions are always checked (whether <stdio.h> is @@ -1686,12 +1688,6 @@ record_international_format (name, assembler_name, 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. NAME is the function identifier. @@ -1700,7 +1696,8 @@ tfaff () PARAMS is the list of argument values. */ void -check_function_format (name, assembler_name, params) +check_function_format (status, name, assembler_name, params) + int *status; tree name; tree assembler_name; tree params; @@ -1715,12 +1712,46 @@ check_function_format (name, assembler_name, params) : (info->name == name)) { /* Yup; check it. */ - check_format_info (info, params); + check_format_info (status, info, params); 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. */ static char *dollar_arguments_used = NULL; @@ -1775,7 +1806,8 @@ init_dollar_format_checking (first_arg_num, params) a $ format is found, *FORMAT is updated to point just after it. */ 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; int dollar_needed; tree params; @@ -1788,7 +1820,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) { if (dollar_needed) { - warning ("missing $ operand number in format"); + status_warning (status, "missing $ operand number in format"); return -1; } else @@ -1809,7 +1841,7 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) { if (dollar_needed) { - warning ("missing $ operand number in format"); + status_warning (status, "missing $ operand number in format"); return -1; } else @@ -1818,13 +1850,13 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) *format = fcp + 1; 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; } if (overflow_flag || argnum == 0 || (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; } if (argnum > dollar_max_arg_used) @@ -1870,17 +1902,18 @@ maybe_read_dollar_number (format, dollar_needed, params, param_ptr) here. */ static void -finish_dollar_format_checking () +finish_dollar_format_checking (status) + int *status; { int i; for (i = 0; i < dollar_max_arg_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); } 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 () PARAMS is the list of argument values. */ static void -check_format_info (info, params) +check_format_info (status, info, params) + int *status; function_format_info *info; tree params; { @@ -1976,7 +2010,7 @@ check_format_info (info, params) if (integer_zerop (format_tree)) { - warning ("null format string"); + status_warning (status, "null format string"); return; } if (TREE_CODE (format_tree) != ADDR_EXPR) @@ -1987,7 +2021,7 @@ check_format_info (info, params) string. These functions typically are declared with first_arg_num == 0, so avoid warning in those cases. */ 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; } format_tree = TREE_OPERAND (format_tree, 0); @@ -1999,16 +2033,16 @@ check_format_info (info, params) string. These functions typically are declared with first_arg_num == 0, so avoid warning in those cases. */ 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; } format_chars = TREE_STRING_POINTER (format_tree); format_length = TREE_STRING_LENGTH (format_tree); if (format_length <= 1) - warning ("zero-length format string"); + status_warning (status, "zero-length format string"); if (format_chars[--format_length] != 0) { - warning ("unterminated format string"); + status_warning (status, "unterminated format string"); return; } /* Skip to first argument to check. */ @@ -2031,19 +2065,19 @@ check_format_info (info, params) if (*format_chars == 0) { 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 && has_operand_number <= 0) - warning ("too many arguments for format"); + status_warning (status, "too many arguments for format"); if (has_operand_number > 0) - finish_dollar_format_checking (); + finish_dollar_format_checking (status); return; } if (*format_chars++ != '%') continue; if (*format_chars == 0) { - warning ("spurious trailing `%%' in format"); + status_warning (status, "spurious trailing `%%' in format"); continue; } if (*format_chars == '%') @@ -2064,7 +2098,7 @@ check_format_info (info, params) else if (has_operand_number != 0) { int opnum; - opnum = maybe_read_dollar_number (&format_chars, + opnum = maybe_read_dollar_number (status, &format_chars, has_operand_number == 1, first_fillin_param, &main_arg_params); @@ -2086,18 +2120,18 @@ check_format_info (info, params) ++format_chars; } 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) { while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0) { 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); 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; } @@ -2114,7 +2148,7 @@ check_format_info (info, params) ++format_chars; } 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') { i = strlen (flag_chars); @@ -2122,7 +2156,7 @@ check_format_info (info, params) flag_chars[i] = 0; 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') ++format_chars; } @@ -2133,7 +2167,7 @@ check_format_info (info, params) if (has_operand_number != 0) { int opnum; - opnum = maybe_read_dollar_number (&format_chars, + opnum = maybe_read_dollar_number (status, &format_chars, 0, first_fillin_param, &main_arg_params); if (opnum == -1) @@ -2148,7 +2182,7 @@ check_format_info (info, params) while (*format_chars != 0 && index (" +#0-'I", *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 { i = strlen (flag_chars); @@ -2160,16 +2194,16 @@ check_format_info (info, params) the space flag will be ignored." */ if (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, the 0 flag will be ignored." */ if (index (flag_chars, '0') != 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) - 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) - 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 == '*') { wide = TRUE; @@ -2178,13 +2212,13 @@ check_format_info (info, params) ++format_chars; if (params == 0) { - tfaff (); + status_warning (status, "too few arguments for format"); return; } if (has_operand_number != 0) { int opnum; - opnum = maybe_read_dollar_number (&format_chars, + opnum = maybe_read_dollar_number (status, &format_chars, has_operand_number == 1, first_fillin_param, ¶ms); @@ -2242,7 +2276,7 @@ check_format_info (info, params) if (has_operand_number != 0) { int opnum; - opnum = maybe_read_dollar_number (&format_chars, + opnum = maybe_read_dollar_number (status, &format_chars, has_operand_number == 1, first_fillin_param, ¶ms); @@ -2260,7 +2294,7 @@ check_format_info (info, params) { if (params == 0) { - tfaff (); + status_warning (status, "too few arguments for format"); return; } cur_param = TREE_VALUE (params); @@ -2327,11 +2361,11 @@ check_format_info (info, params) { /* Warn if the length modifier is non-standard. */ 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); else if ((length_chars_std == STD_C99 && !flag_isoc99) || (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); } if (*format_chars == 'a' && info->format_type == scanf_format_type @@ -2346,13 +2380,13 @@ check_format_info (info, params) } } 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; if (format_char == 0 || (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; } format_chars++; @@ -2363,51 +2397,51 @@ check_format_info (info, params) if (fci->format_chars == 0) { if (ISGRAPH(format_char)) - warning ("unknown conversion type character `%c' in format", + status_warning (status, "unknown conversion type character `%c' in format", format_char); else - warning ("unknown conversion type character 0x%x in format", + status_warning (status, "unknown conversion type character 0x%x in format", format_char); continue; } if (pedantic) { 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); else if ((fci->std == STD_C99 && !flag_isoc99) || (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); if (index (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) - 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')) - 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) - 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 || (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); 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) - 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) { - 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. */ aflag = 0; } /* The a flag is a GNU extension. */ 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 == '[') { /* Skip over scan set, in case it happens to have '%' in it. */ @@ -2421,18 +2455,18 @@ check_format_info (info, params) ++format_chars; if (*format_chars != ']') /* The end of the format string was reached. */ - warning ("no closing `]' for `%%[' format"); + status_warning (status, "no closing `]' for `%%[' format"); } if (suppressed) { 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; } for (i = 0; flag_chars[i] != 0; ++i) { 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); } if (info->format_type == strftime_format_type) @@ -2441,7 +2475,7 @@ check_format_info (info, params) && (format_char == 'd' || format_char == 'i' || format_char == 'o' || format_char == 'u' || 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); wanted_type = (fci->types[length_chars_val].type ? *fci->types[length_chars_val].type : 0); @@ -2449,14 +2483,14 @@ check_format_info (info, params) wanted_type_std = fci->types[length_chars_val].std; 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); /* Heuristic: skip one argument when an invalid length/type combination is encountered. */ arg_num++; if (params == 0) { - tfaff (); + status_warning (status, "too few arguments for format"); return; } params = TREE_CHAIN (params); @@ -2470,11 +2504,11 @@ check_format_info (info, params) && wanted_type_std > fci->std) { 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); else if ((wanted_type_std == STD_C99 && !flag_isoc99) || (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); } @@ -2484,7 +2518,7 @@ check_format_info (info, params) if (fci->pointer_count == 0 && wanted_type == void_type_node) { 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 { @@ -2498,14 +2532,14 @@ check_format_info (info, params) ++arg_num; if (has_operand_number > 0) { - warning ("missing $ operand number in format"); + status_warning (status, "missing $ operand number in format"); return; } else has_operand_number = 0; if (params == 0) { - tfaff (); + status_warning (status, "too few arguments for format"); return; } } @@ -2532,7 +2566,7 @@ check_format_info (info, params) } 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) /* Check the argument types from a single format conversion (possibly including width and precision arguments). */ static void -check_format_types (types) +check_format_types (status, types) + int *status; format_wanted_type *types; { for (; types != 0; types = types->next) @@ -2596,7 +2631,7 @@ check_format_types (types) && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c' || (DECL_P (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 indirection, then this makes the types technically @@ -2606,16 +2641,16 @@ check_format_types (types) && (TYPE_READONLY (cur_type) || TYPE_VOLATILE (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); } else { 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 - 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; } } @@ -2709,10 +2744,10 @@ check_format_types (types) && strcmp (types->wanted_type_name, that) != 0) this = types->wanted_type_name; 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); 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); } } } |