[PATCH] Fix undefined behavior in ira-build.c
Jakub Jelinek
jakub@redhat.com
Fri Jun 27 09:37:00 GMT 2014
On Fri, Jun 27, 2014 at 11:34:48AM +0200, Richard Biener wrote:
> On Fri, Jun 27, 2014 at 9:16 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > Hi!
> >
> > This fixes the most common source of the new runtime diagnostics
> > during bootstrap-ubsan, if num is 0, ira_object_id_map is often
> > 0 as well.
> >
> > Ok for trunk/4.9?
>
> If it's also sometimes 1 then why not if (num > 1) - just as optimization...
Sure, if Vlad is ok with the patch, consider it changed to num > 1.
> > 2014-06-27 Jakub Jelinek <jakub@redhat.com>
> >
> > * ira-build.c (sort_conflict_id_map): Don't call
> > qsort if num is 0, as ira_object_id_map might be NULL.
> >
> > --- gcc/ira-build.c.jj 2014-05-30 10:51:16.000000000 +0200
> > +++ gcc/ira-build.c 2014-06-26 20:21:43.428987181 +0200
> > @@ -2821,8 +2821,9 @@ sort_conflict_id_map (void)
> > FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
> > ira_object_id_map[num++] = obj;
> > }
> > - qsort (ira_object_id_map, num, sizeof (ira_object_t),
> > - object_range_compare_func);
> > + if (num)
> > + qsort (ira_object_id_map, num, sizeof (ira_object_t),
> > + object_range_compare_func);
> > for (i = 0; i < num; i++)
> > {
> > ira_object_t obj = ira_object_id_map[i];
> >
> > Jakub
Jakub
More information about the Gcc-patches
mailing list