On 06/20/2017 03:27 AM, Jakub Jelinek wrote:
Hi!

bootstrap-ubsan revealed many
../../gcc/ira-costs.c:1747:20: runtime error: member access within null pointer 
of type 'cost_classes *[107]'
issues.  The problem is that cost_classes_ptr is sometimes NULL, but
in those cases we have early exit:
           if (! allocno_p)
             {
               if (regno_reg_rtx[i] == NULL_RTX)
                 continue;      // <----- HERE
               memcpy (temp_costs, COSTS (costs, i), struct_costs_size);
               i_mem_cost = temp_costs->mem_cost;
             }
           else
             {
               if (ira_regno_allocno_map[i] == NULL)
                 continue;      // <----- or HERE
...
             }
Still, cost_classes_ptr->classes where classes is an array is UB when
cost_classes_ptr is NULL, so this patch moves it after the if (...) continue;
in both branches (because it is needed both later in the else ...
and after the whole if.

Bootstrapped/regtested on x86_64-linux and i686-linux (with
bootstrap-ubsan), ok for trunk?
Sure.

Jakub, thank you for addressing the issue.
2017-06-20  Jakub Jelinek  <ja...@redhat.com>

        * ira-costs.c (find_costs_and_classes): Initialize cost_classes later
        to make sure not to dereference a NULL cost_classes_ptr pointer.


Reply via email to