]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bb-reorder.c (copy_bb_p): Don't overflow size calculation.
authorAlan Modra <amodra@gmail.com>
Mon, 3 Jun 2019 17:35:47 +0000 (03:05 +0930)
committerJeff Law <law@gcc.gnu.org>
Mon, 3 Jun 2019 17:35:47 +0000 (11:35 -0600)
* bb-reorder.c (copy_bb_p): Don't overflow size calculation.
(get_uncond_jump_length): Assert length less than INT_MAX and
non-negative.

From-SVN: r271877

gcc/ChangeLog
gcc/bb-reorder.c

index d6dd1bd5605a3bad8ea22d64730ec3833b1aeacc..ae20f9579aa2ca6a52accdd88d729410a8d87e24 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-03  Alan Modra  <amodra@gmail.com>
+
+       * bb-reorder.c (copy_bb_p): Don't overflow size calculation.
+       (get_uncond_jump_length): Assert length less than INT_MAX and
+       non-negative.
+
 2019-06-03  Wilco Dijkstra  <wdijkstr@arm.com>
 
        PR middle-end/64242
index e4ae8b89c0969d551a010d3b9795f1f4e0e3f6bb..c21d204627e5205da09e60b17d909a7386ab9e3f 100644 (file)
@@ -1357,8 +1357,8 @@ connect_traces (int n_traces, struct trace *traces)
 static bool
 copy_bb_p (const_basic_block bb, int code_may_grow)
 {
-  int size = 0;
-  int max_size = uncond_jump_length;
+  unsigned int size = 0;
+  unsigned int max_size = uncond_jump_length;
   rtx_insn *insn;
 
   if (EDGE_COUNT (bb->preds) < 2)
@@ -1376,7 +1376,11 @@ copy_bb_p (const_basic_block bb, int code_may_grow)
   FOR_BB_INSNS (bb, insn)
     {
       if (INSN_P (insn))
-       size += get_attr_min_length (insn);
+       {
+         size += get_attr_min_length (insn);
+         if (size > max_size)
+           break;
+       }
     }
 
   if (size <= max_size)
@@ -1385,7 +1389,7 @@ copy_bb_p (const_basic_block bb, int code_may_grow)
   if (dump_file)
     {
       fprintf (dump_file,
-              "Block %d can't be copied because its size = %d.\n",
+              "Block %d can't be copied because its size = %u.\n",
               bb->index, size);
     }
 
@@ -1397,7 +1401,7 @@ copy_bb_p (const_basic_block bb, int code_may_grow)
 int
 get_uncond_jump_length (void)
 {
-  int length;
+  unsigned int length;
 
   start_sequence ();
   rtx_code_label *label = emit_label (gen_label_rtx ());
@@ -1405,6 +1409,7 @@ get_uncond_jump_length (void)
   length = get_attr_min_length (jump);
   end_sequence ();
 
+  gcc_assert (length < INT_MAX);
   return length;
 }