Commit 74ff4629 by Joseph Myers Committed by Joseph Myers

c-common.h (warn_missing_format_attribute): New variable.

	* c-common.h (warn_missing_format_attribute): New variable.
	* c-decl.c (warn_missing_format_attribute): New variable.
	(c_decode_option): Decode -Wmissing-format-attribute and
	-Wno-missing-format-attribute.
	* c-common.c (check_function_format): If
	-Wmissing-format-attribute, give a warning where a vprintf or
	vscanf function is called by a function without its own printf or
	scanf attribute.
	* toplev.c (documented_lang_options): Add
	-Wmissing-format-attribute.
	* invoke.texi: Document -Wmissing-format-attribute.

cp:
	* decl2.c (warn_missing_format_attribute): New variable.
	(lang_decode_option): Decode -Wmissing-format-attribute.

testsuite:
	* gcc.dg/format-miss-1.c: New test.

From-SVN: r36897
parent 1d3b0e2c
2000-10-17 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.h (warn_missing_format_attribute): New variable.
* c-decl.c (warn_missing_format_attribute): New variable.
(c_decode_option): Decode -Wmissing-format-attribute and
-Wno-missing-format-attribute.
* c-common.c (check_function_format): If
-Wmissing-format-attribute, give a warning where a vprintf or
vscanf function is called by a function without its own printf or
scanf attribute.
* toplev.c (documented_lang_options): Add
-Wmissing-format-attribute.
* invoke.texi: Document -Wmissing-format-attribute.
2000-10-17 Marc Espie <espie@openbsd.org>
* invoke.texi (-shared): Insist on requiring code generation flags
......
......@@ -1926,7 +1926,9 @@ record_international_format (name, assembler_name, format_num)
NAME is the function identifier.
ASSEMBLER_NAME is the function's assembler identifier.
(Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
PARAMS is the list of argument values. */
PARAMS is the list of argument values. Also, if -Wmissing-format-attribute,
warn for calls to vprintf or vscanf in functions with no such format
attribute themselves. */
void
check_function_format (status, name, assembler_name, params)
......@@ -1946,6 +1948,20 @@ check_function_format (status, name, assembler_name, params)
{
/* Yup; check it. */
check_format_info (status, info, params);
if (warn_missing_format_attribute && info->first_arg_num == 0
&& (format_types[info->format_type].flags & FMT_FLAG_ARG_CONVERT))
{
function_format_info *info2;
for (info2 = function_format_list; info2; info2 = info2->next)
if ((info2->assembler_name
? (info2->assembler_name == DECL_ASSEMBLER_NAME (current_function_decl))
: (info2->name == DECL_NAME (current_function_decl)))
&& info2->format_type == info->format_type)
break;
if (info2 == NULL)
warning ("function might be possible candidate for `%s' format attribute",
format_types[info->format_type].name);
}
break;
}
}
......
......@@ -337,6 +337,10 @@ extern int flag_const_strings;
extern int warn_format;
/* Warn about functions which might be candidates for format attributes. */
extern int warn_missing_format_attribute;
/* Nonzero means do some things the same way PCC does. */
extern int flag_traditional;
......
......@@ -416,6 +416,10 @@ int warn_cast_qual;
int warn_bad_function_cast;
/* Warn about functions which might be candidates for format attributes. */
int warn_missing_format_attribute;
/* Warn about traditional constructs whose meanings changed in ANSI C. */
int warn_traditional;
......@@ -716,6 +720,10 @@ c_decode_option (argc, argv)
warn_missing_noreturn = 1;
else if (!strcmp (p, "-Wno-missing-noreturn"))
warn_missing_noreturn = 0;
else if (!strcmp (p, "-Wmissing-format-attribute"))
warn_missing_format_attribute = 1;
else if (!strcmp (p, "-Wno-missing-format-attribute"))
warn_missing_format_attribute = 0;
else if (!strcmp (p, "-Wpointer-arith"))
warn_pointer_arith = 1;
else if (!strcmp (p, "-Wno-pointer-arith"))
......
2000-10-17 Joseph S. Myers <jsm28@cam.ac.uk>
* decl2.c (warn_missing_format_attribute): New variable.
(lang_decode_option): Decode -Wmissing-format-attribute.
2000-10-16 Mark Mitchell <mark@codesourcery.com>
* typeck.c (qualify_type): Remove.
......
......@@ -290,6 +290,10 @@ int warn_float_equal = 0;
int warn_format;
/* Warn about functions which might be candidates for format attributes. */
int warn_missing_format_attribute;
/* Warn about a subscript that has type char. */
int warn_char_subscripts;
......@@ -751,6 +755,8 @@ lang_decode_option (argc, argv)
warn_float_equal = setting;
else if (!strcmp (p, "format"))
warn_format = setting;
else if (!strcmp (p, "missing-format-attribute"))
warn_missing_format_attribute = setting;
else if (!strcmp (p, "conversion"))
warn_conversion = setting;
else if (!strcmp (p, "parentheses"))
......
......@@ -2012,6 +2012,16 @@ be taken to manually verify functions actually do not ever return before
adding the @code{noreturn} attribute, otherwise subtle code generation
bugs could be introduced.
@item -Wmissing-format-attribute
If @samp{-Wformat} is enabled, also warn about functions which might be
candidates for @code{format} attributes. Note these are only possible
candidates, not absolute ones. GCC will guess that @code{format}
attributes might be appropriate for any function that calls a function
like @code{vprintf} or @code{vscanf}, but this might not always be the
case, and some functions for which @code{format} attributes are
appropriate may not be detected. This option has no effect unless
@samp{-Wformat} is enabled (possibly by @samp{-Wall}).
@item -Wpacked
Warn if a structure is given the packed attribute, but the packed
attribute has no effect on the layout or size of the structure.
......
2000-10-17 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format-miss-1.c: New test.
2000-10-16 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/20001013-1.c: New test.
......
/* Test for warnings for missing format attributes. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat -Wmissing-format-attribute" } */
#include <stdarg.h>
extern int vprintf (const char *restrict, va_list);
extern int vscanf (const char *restrict, va_list);
void
foo (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vprintf (fmt, ap); /* { dg-warning "candidate" "printf attribute warning" } */
va_end (ap);
}
void
bar (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vscanf (fmt, ap); /* { dg-warning "candidate" "scanf attribute warning" } */
va_end (ap);
}
__attribute__((__format__(__printf__, 1, 2))) void
foo2 (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vprintf (fmt, ap);
va_end (ap);
}
void
vfoo (const char *fmt, va_list arg)
{
vprintf (fmt, arg); /* { dg-warning "candidate" "printf attribute warning 2" } */
}
......@@ -1207,6 +1207,9 @@ documented_lang_options[] =
{ "-Wmissing-noreturn",
"Warn about functions which might be candidates for attribute noreturn" },
{ "-Wno-missing-noreturn", "" },
{ "-Wmissing-format-attribute",
"Warn about functions which might be candidates for format attributes" },
{ "-Wno-missing-format-attribute", "" },
{ "-Wcast-qual", "Warn about casts which discard qualifiers"},
{ "-Wno-cast-qual", "" },
{ "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
......
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