re PR c/83966 (ICE in check_function_arguments at gcc/c-family/c-common.c:5617)
authorMarek Polacek <polacek@redhat.com>
Mon, 29 Jan 2018 18:20:01 +0000 (18:20 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 29 Jan 2018 18:20:01 +0000 (18:20 +0000)
PR c/83966
* c-format.c (check_function_format): Check current_function_decl.

* gcc.dg/format/Wsuggest-attribute-1.c: New test.

From-SVN: r257159

gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/Wsuggest-attribute-1.c [new file with mode: 0644]

index 335eeeb10b6aeb7dbe3e55d1c8da66c95d00f5e5..7a142886acccb035791b26b7cb5ee257256dafc2 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-29  Marek Polacek  <polacek@redhat.com>
+
+       PR c/83966
+       * c-format.c (check_function_format): Check current_function_decl.
+
 2018-01-27  Jakub Jelinek  <jakub@redhat.com>
 
        * c-cppbuiltin.c (c_cpp_builtins): Use ggc_strdup for the fp_suffix
index 7a69d5a295cf639875258128029170cd00829bf1..3f4f83af2190a8d728ba7c81d058666eb6b935df 100644 (file)
@@ -1110,7 +1110,9 @@ check_function_format (tree attrs, int nargs, tree *argarray,
             from the format attribute if the called function is decorated
             with it.  Avoid using calls with string literal formats for
             guidance since those are unlikely to be viable candidates.  */
-         if (warn_suggest_attribute_format && info.first_arg_num == 0
+         if (warn_suggest_attribute_format
+             && current_function_decl != NULL_TREE
+             && info.first_arg_num == 0
              && (format_types[info.format_type].flags
                  & (int) FMT_FLAG_ARG_CONVERT)
              /* c_strlen will fail for a function parameter but succeed
index 18e19afcd0abdd6e70dc2fd0982610e67bf1e2f3..3713a81227cea5ef13cea48ba69927bdc2932a02 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-29  Marek Polacek  <polacek@redhat.com>
+
+       PR c/83966
+       * gcc.dg/format/Wsuggest-attribute-1.c: New test.
+
 2018-01-29  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/84057
diff --git a/gcc/testsuite/gcc.dg/format/Wsuggest-attribute-1.c b/gcc/testsuite/gcc.dg/format/Wsuggest-attribute-1.c
new file mode 100644 (file)
index 0000000..5b6fb05
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR c/83966 */
+/* { dg-do compile } */
+/* { dg-options "-Wsuggest-attribute=format" } */
+
+#include "format.h"
+
+va_list va;
+const char *f;
+__typeof (vsnprintf ("foo", 0U, f, va)) T;