Patch for c/1017 (-Wmissing-format-attribute)
Joseph S. Myers
jsm28@cam.ac.uk
Sat Dec 9 07:59:00 GMT 2000
This patch addresses c/1017 by making -Wmissing-format-attribute only
suggest adding a format attribute if there's a parameter to which to
add such an attribute.
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit?
gcc/ChangeLog:
2000-12-09 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (check_function_format): Don't suggest adding format
attributes to functions with no parameter to which to add them.
gcc/testsuite/ChangeLog:
2000-12-09 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format-miss-2.c: New test.
--- c-common.c.orig Thu Dec 7 13:04:29 2000
+++ c-common.c Sat Dec 9 11:51:19 2000
@@ -2047,8 +2047,25 @@ check_function_format (status, name, ass
&& 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);
+ {
+ /* Check if the current function has a parameter to which
+ the format attribute could be attached; if not, it
+ can't be a candidate for a format attribute, despite
+ the vprintf-like or vscanf-like call. */
+ tree args;
+ for (args = DECL_ARGUMENTS (current_function_decl);
+ args != 0;
+ args = TREE_CHAIN (args))
+ {
+ if (TREE_CODE (TREE_TYPE (args)) == POINTER_TYPE
+ && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (args)))
+ == char_type_node))
+ break;
+ }
+ if (args != 0)
+ warning ("function might be possible candidate for `%s' format attribute",
+ format_types[info->format_type].name);
+ }
}
break;
}
--- testsuite/gcc.dg/format-miss-2.c.orig Fri Sep 11 11:31:59 1998
+++ testsuite/gcc.dg/format-miss-2.c Sat Dec 9 11:56:12 2000
@@ -0,0 +1,18 @@
+/* Test for warnings for missing format attributes. Don't warn if no
+ relevant parameters for a format attribute; see c/1017. */
+/* 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);
+
+void
+foo (int i, ...)
+{
+ va_list ap;
+ va_start (ap, i);
+ vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */
+ va_end (ap);
+}
--
Joseph S. Myers
jsm28@cam.ac.uk
More information about the Gcc-patches
mailing list