Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl3 The syslog format attribute is a superset of t...



details:   https://anonhg.NetBSD.org/src/rev/d95cd186995b
branches:  trunk
changeset: 433440:d95cd186995b
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 14 20:46:46 2018 +0000

description:
The syslog format attribute is a superset of the printf format attribute
so allow functions marked with the printf format attribute to call syslog
without producing warnings with -Wmissing-format-attribute.

diffstat:

 external/gpl3/gcc.old/dist/gcc/c-family/c-format.c |  46 ++++++++++++---------
 external/gpl3/gcc.old/dist/gcc/c-family/c-format.h |   2 +
 external/gpl3/gcc/dist/gcc/c-family/c-format.c     |  46 ++++++++++++---------
 external/gpl3/gcc/dist/gcc/c-family/c-format.h     |   2 +
 4 files changed, 56 insertions(+), 40 deletions(-)

diffs (280 lines):

diff -r d8cceca11e7e -r d95cd186995b external/gpl3/gcc.old/dist/gcc/c-family/c-format.c
--- a/external/gpl3/gcc.old/dist/gcc/c-family/c-format.c        Fri Sep 14 20:38:38 2018 +0000
+++ b/external/gpl3/gcc.old/dist/gcc/c-family/c-format.c        Fri Sep 14 20:46:46 2018 +0000
@@ -887,70 +887,70 @@
     printf_flag_specs, printf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
     'w', 0, 'p', 0, 'L', 0,
-    &integer_type_node, &integer_type_node
+    &integer_type_node, &integer_type_node, format_type_error
   },
   { "asm_fprintf",   asm_fprintf_length_specs,  asm_fprintf_char_table, " +#0-", NULL,
     asm_fprintf_flag_specs, asm_fprintf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
     'w', 0, 'p', 0, 'L', 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gcc_diag",   gcc_diag_length_specs,  gcc_diag_char_table, "q+#", NULL,
     gcc_diag_flag_specs, gcc_diag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_tdiag",   gcc_tdiag_length_specs,  gcc_tdiag_char_table, "q+#", NULL,
     gcc_tdiag_flag_specs, gcc_tdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_cdiag",   gcc_cdiag_length_specs,  gcc_cdiag_char_table, "q+#", NULL,
     gcc_cdiag_flag_specs, gcc_cdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_cxxdiag",   gcc_cxxdiag_length_specs,  gcc_cxxdiag_char_table, "q+#", NULL,
     gcc_cxxdiag_flag_specs, gcc_cxxdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_gfc", gcc_gfc_length_specs, gcc_gfc_char_table, "q+#", NULL,
     gcc_gfc_flag_specs, gcc_gfc_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "NSString",   NULL,  NULL, NULL, NULL,
     NULL, NULL,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL, 0, 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
     scanf_flag_specs, scanf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
     'w', 0, 0, '*', 'L', 'm',
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_strftime", NULL,                 time_char_table,  "_-0^#", "EO",
     strftime_flag_specs, strftime_flag_pairs,
     FMT_FLAG_FANCY_PERCENT_OK|FMT_FLAG_M_OK, 'w', 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
     strfmon_flag_specs, strfmon_flag_pairs,
     FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_syslog",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
     printf_flag_specs, printf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK|FMT_FLAG_M_OK,
     'w', 0, 'p', 0, 'L', 0,
-    &integer_type_node, &integer_type_node
+    &integer_type_node, &integer_type_node, printf_format_type
   },
 };
 
@@ -1098,19 +1098,25 @@
                params = tree_cons (NULL_TREE, argarray[i], params);
              check_format_info (&info, params);
            }
+         const format_kind_info *fi = &format_types[info.format_type];
          if (warn_suggest_attribute_format && info.first_arg_num == 0
-             && (format_types[info.format_type].flags
-                 & (int) FMT_FLAG_ARG_CONVERT))
+             && (fi->flags & (int) FMT_FLAG_ARG_CONVERT))
            {
              tree c;
              for (c = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
                   c;
                   c = TREE_CHAIN (c))
-               if (is_attribute_p ("format", TREE_PURPOSE (c))
-                   && (decode_format_type (IDENTIFIER_POINTER
-                                           (TREE_VALUE (TREE_VALUE (c))))
-                       == info.format_type))
-                 break;
+               {
+                 if (!is_attribute_p ("format", TREE_PURPOSE (c)))
+                    continue;
+                 int format_type = decode_format_type (
+                     IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (c))));
+                 if (format_type == format_type_error)
+                    continue;
+                 if (format_type == info.format_type ||
+                     format_type == fi->parent_format_type)
+                   break;
+               }
              if (c == NULL_TREE)
                {
                  /* Check if the current function has a parameter to which
@@ -1130,7 +1136,7 @@
                  if (args != 0)
                    warning (OPT_Wsuggest_attribute_format, "function might "
                             "be possible candidate for %qs format attribute",
-                            format_types[info.format_type].name);
+                            fi->name);
                }
            }
        }
diff -r d8cceca11e7e -r d95cd186995b external/gpl3/gcc.old/dist/gcc/c-family/c-format.h
--- a/external/gpl3/gcc.old/dist/gcc/c-family/c-format.h        Fri Sep 14 20:38:38 2018 +0000
+++ b/external/gpl3/gcc.old/dist/gcc/c-family/c-format.h        Fri Sep 14 20:46:46 2018 +0000
@@ -253,6 +253,8 @@
   /* Pointer to type of argument expected if '*' is used for a precision,
      or NULL if '*' not used for precisions.  */
   tree *precision_type;
+  /* A format type that is a subset of our format */
+  int  parent_format_type;
 };
 
 #define T_I    &integer_type_node
diff -r d8cceca11e7e -r d95cd186995b external/gpl3/gcc/dist/gcc/c-family/c-format.c
--- a/external/gpl3/gcc/dist/gcc/c-family/c-format.c    Fri Sep 14 20:38:38 2018 +0000
+++ b/external/gpl3/gcc/dist/gcc/c-family/c-format.c    Fri Sep 14 20:46:46 2018 +0000
@@ -887,70 +887,70 @@
     printf_flag_specs, printf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
     'w', 0, 'p', 0, 'L', 0,
-    &integer_type_node, &integer_type_node
+    &integer_type_node, &integer_type_node, format_type_error
   },
   { "asm_fprintf",   asm_fprintf_length_specs,  asm_fprintf_char_table, " +#0-", NULL,
     asm_fprintf_flag_specs, asm_fprintf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
     'w', 0, 'p', 0, 'L', 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gcc_diag",   gcc_diag_length_specs,  gcc_diag_char_table, "q+#", NULL,
     gcc_diag_flag_specs, gcc_diag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_tdiag",   gcc_tdiag_length_specs,  gcc_tdiag_char_table, "q+#", NULL,
     gcc_tdiag_flag_specs, gcc_tdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_cdiag",   gcc_cdiag_length_specs,  gcc_cdiag_char_table, "q+#", NULL,
     gcc_cdiag_flag_specs, gcc_cdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_cxxdiag",   gcc_cxxdiag_length_specs,  gcc_cxxdiag_char_table, "q+#", NULL,
     gcc_cxxdiag_flag_specs, gcc_cxxdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 'p', 0, 'L', 0,
-    NULL, &integer_type_node
+    NULL, &integer_type_node, format_type_error
   },
   { "gcc_gfc", gcc_gfc_length_specs, gcc_gfc_char_table, "q+#", NULL,
     gcc_gfc_flag_specs, gcc_gfc_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_M_OK,
     0, 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "NSString",   NULL,  NULL, NULL, NULL,
     NULL, NULL,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL, 0, 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
     scanf_flag_specs, scanf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
     'w', 0, 0, '*', 'L', 'm',
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_strftime", NULL,                 time_char_table,  "_-0^#", "EO",
     strftime_flag_specs, strftime_flag_pairs,
     FMT_FLAG_FANCY_PERCENT_OK|FMT_FLAG_M_OK, 'w', 0, 0, 0, 0, 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
     strfmon_flag_specs, strfmon_flag_pairs,
     FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
-    NULL, NULL
+    NULL, NULL, format_type_error
   },
   { "gnu_syslog",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
     printf_flag_specs, printf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK|FMT_FLAG_M_OK,
     'w', 0, 'p', 0, 'L', 0,
-    &integer_type_node, &integer_type_node
+    &integer_type_node, &integer_type_node, printf_format_type
   },
 };
 
@@ -1098,19 +1098,25 @@
                params = tree_cons (NULL_TREE, argarray[i], params);
              check_format_info (&info, params);
            }
+         const format_kind_info *fi = &format_types[info.format_type];
          if (warn_suggest_attribute_format && info.first_arg_num == 0
-             && (format_types[info.format_type].flags
-                 & (int) FMT_FLAG_ARG_CONVERT))
+             && (fi->flags & (int) FMT_FLAG_ARG_CONVERT))
            {
              tree c;
              for (c = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
                   c;
                   c = TREE_CHAIN (c))
-               if (is_attribute_p ("format", TREE_PURPOSE (c))
-                   && (decode_format_type (IDENTIFIER_POINTER
-                                           (TREE_VALUE (TREE_VALUE (c))))
-                       == info.format_type))
-                 break;
+               {
+                 if (!is_attribute_p ("format", TREE_PURPOSE (c)))
+                    continue;
+                 int format_type = decode_format_type (
+                     IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (c))));
+                 if (format_type == format_type_error)
+                    continue;
+                 if (format_type == info.format_type ||
+                     format_type == fi->parent_format_type)
+                   break;
+               }
              if (c == NULL_TREE)
                {
                  /* Check if the current function has a parameter to which
@@ -1130,7 +1136,7 @@
                  if (args != 0)
                    warning (OPT_Wsuggest_attribute_format, "function might "
                             "be possible candidate for %qs format attribute",
-                            format_types[info.format_type].name);
+                            fi->name);
                }
            }
        }
diff -r d8cceca11e7e -r d95cd186995b external/gpl3/gcc/dist/gcc/c-family/c-format.h
--- a/external/gpl3/gcc/dist/gcc/c-family/c-format.h    Fri Sep 14 20:38:38 2018 +0000
+++ b/external/gpl3/gcc/dist/gcc/c-family/c-format.h    Fri Sep 14 20:46:46 2018 +0000
@@ -253,6 +253,8 @@
   /* Pointer to type of argument expected if '*' is used for a precision,
      or NULL if '*' not used for precisions.  */
   tree *precision_type;
+  /* A format type that is a subset of our format */
+  int  parent_format_type;
 };
 
 #define T_I    &integer_type_node



Home | Main Index | Thread Index | Old Index