From e45046aeda064dac8461f0037eb221cca677c9d0 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sat, 9 Dec 2000 21:26:56 +0000 Subject: [PATCH] c-common.c (check_function_format): Don't suggest adding format attributes to functions with no parameter to which... * c-common.c (check_function_format): Don't suggest adding format attributes to functions with no parameter to which to add them. testsuite: * gcc.dg/format-miss-2.c: New test. From-SVN: r38163 --- gcc/ChangeLog | 5 +++++ gcc/c-common.c | 21 +++++++++++++++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/format-miss-2.c | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/format-miss-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e8bc30670f9..ea745cd0bc9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2000-12-09 Joseph S. Myers + + * c-common.c (check_function_format): Don't suggest adding format + attributes to functions with no parameter to which to add them. + 2000-12-09 Nick Clifton * config/arm/arm.c (arm_expand_prologue): Mark the generated diff --git a/gcc/c-common.c b/gcc/c-common.c index 2baba027a1f..1e766e6ecda 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2047,8 +2047,25 @@ check_function_format (status, name, assembler_name, params) && 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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5282938e4af..de2e47ad6c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2000-12-09 Joseph S. Myers + + * gcc.dg/format-miss-2.c: New test. + 2000-12-09 Neil Booth * gcc.dg/cpp/lineflags.c: New tests. diff --git a/gcc/testsuite/gcc.dg/format-miss-2.c b/gcc/testsuite/gcc.dg/format-miss-2.c new file mode 100644 index 00000000000..b7c55019e3e --- /dev/null +++ b/gcc/testsuite/gcc.dg/format-miss-2.c @@ -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 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wmissing-format-attribute" } */ + +#include + +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); +} -- 2.30.2