Fix integer overflow in stats of trees.
authorMartin Liska <mliska@suse.cz>
Fri, 12 Jan 2018 14:45:35 +0000 (15:45 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 12 Jan 2018 14:45:35 +0000 (14:45 +0000)
2018-01-12  Martin Liska  <mliska@suse.cz>

* tree-core.h: Use uint64_t instead of int.
* tree.c (tree_node_counts): Likewise.
(tree_node_sizes): Likewise.
(dump_tree_statistics): Use PRIu64 in printf format.

From-SVN: r256583

gcc/ChangeLog
gcc/tree-core.h
gcc/tree.c

index 88417f738bacc495cd4559d4def4de1fe256f63c..730e8edd02b0c23df96a788198aab38b0cc78103 100644 (file)
@@ -1,3 +1,10 @@
+2018-01-12  Martin Liska  <mliska@suse.cz>
+
+       * tree-core.h: Use uint64_t instead of int.
+       * tree.c (tree_node_counts): Likewise.
+       (tree_node_sizes): Likewise.
+       (dump_tree_statistics): Use PRIu64 in printf format.
+
 2018-01-12  Martin Liska  <mliska@suse.cz>
 
        * Makefile.in: As qsort_chk is implemented in vec.c, add
index 56acd10a6535884f9b6591338f48a25ad81e9a6d..478c631998cf17139081c65d81f179dfb982b67d 100644 (file)
@@ -2123,8 +2123,8 @@ extern GTY(()) tree integer_types[itk_none];
 extern GTY(()) tree sizetype_tab[(int) stk_type_kind_last];
 
 /* Arrays for keeping track of tree node statistics.  */
-extern int tree_node_counts[];
-extern int tree_node_sizes[];
+extern uint64_t tree_node_counts[];
+extern uint64_t tree_node_sizes[];
 
 /* True if we are in gimple form and the actions of the folders need to
    be restricted.  False if we are not in gimple form and folding is not
index 722ce021b674beec83a2cca86334d1cbc567d360..c008a55804c1e342eb8e2c0c6658ef9e8a831d3b 100644 (file)
@@ -129,9 +129,9 @@ extern int _obstack_allocated_p (struct obstack *h, void *obj);
 
 /* Statistics-gathering stuff.  */
 
-static int tree_code_counts[MAX_TREE_CODES];
-int tree_node_counts[(int) all_kinds];
-int tree_node_sizes[(int) all_kinds];
+static uint64_t tree_code_counts[MAX_TREE_CODES];
+uint64_t tree_node_counts[(int) all_kinds];
+uint64_t tree_node_sizes[(int) all_kinds];
 
 /* Keep in sync with tree.h:enum tree_node_kind.  */
 static const char * const tree_node_kind_names[] = {
@@ -9123,25 +9123,27 @@ dump_tree_statistics (void)
   if (GATHER_STATISTICS)
     {
       int i;
-      int total_nodes, total_bytes;
+      uint64_t total_nodes, total_bytes;
       fprintf (stderr, "\nKind                   Nodes      Bytes\n");
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
       total_nodes = total_bytes = 0;
       for (i = 0; i < (int) all_kinds; i++)
        {
-         fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
-                  tree_node_counts[i], tree_node_sizes[i]);
+         fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n",
+                  tree_node_kind_names[i], tree_node_counts[i],
+                  tree_node_sizes[i]);
          total_nodes += tree_node_counts[i];
          total_bytes += tree_node_sizes[i];
        }
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
-      fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
+      fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", "Total",
+              total_nodes, total_bytes);
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
       fprintf (stderr, "Code                   Nodes\n");
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
       for (i = 0; i < (int) MAX_TREE_CODES; i++)
-       fprintf (stderr, "%-32s %7d\n", get_tree_code_name ((enum tree_code) i),
-                 tree_code_counts[i]);
+       fprintf (stderr, "%-32s %7" PRIu64 "\n",
+                get_tree_code_name ((enum tree_code) i), tree_code_counts[i]);
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
       fprintf (stderr, "\n");
       ssanames_print_statistics ();