On Fri, Jan 11, 2019 at 11:42:31AM -0700, Jeff Law wrote:
> On 1/10/19 12:19 AM, Alan Modra wrote:
> > bb-reorder is quite seriously broken if get_attr_min_length should
> > return INT_MAX, which it does for hppa on branches with r267666.
> Presumably you're referring to the overflows and such?

Yes.  Even get_uncond_jump_length would have been INT_MAX.  All of
the predicates deciding on whether to copy or reorder blocks were
therefore broken.

The following is fairly obvious and would stop some of the silliness,
but I guess now is not the time to propose this sort of patch.

        * bb-reorder.c (copy_bb_p): Don't overflow size calculation.
        (get_uncond_jump_length): Assert length less than INT_MAX and
        non-negative.

diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index e4ae8b89c09..c21d204627e 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -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;
 }
 

-- 
Alan Modra
Australia Development Lab, IBM

Reply via email to