Hi!

We have
#define DEPS_LIST_FIRST(L) ((L)->first)
and first is the field of the struct, so for the case when list is
NULL we do linkp = &list->first; which actually gives us NULL too, but with
UB.  From my analysis of the scheduler code, we should never use linkp (or
anything else in the iterator) after sd_iterator_cond returned false (don't
iterate anymore), so I think it is just fine to keep it pointing to the
previous entry (where *linkp is NULL), instead of setting linkp effectively
to NULL.  All uses of linkp dereference linkp anyway.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-09-02  Jakub Jelinek  <ja...@redhat.com>

        PR rtl-optimization/77425
        * sched-int.h (sd_iterator_cond): Don't update it_ptr->linkp if list
        is NULL.

--- gcc/sched-int.h.jj  2016-03-15 17:10:19.000000000 +0100
+++ gcc/sched-int.h     2016-09-01 11:49:52.057719797 +0200
@@ -1624,10 +1624,11 @@ sd_iterator_cond (sd_iterator_def *it_pt
              sd_next_list (it_ptr->insn,
                            &it_ptr->types, &list, &it_ptr->resolved_p);
 
-             it_ptr->linkp = &DEPS_LIST_FIRST (list);
-
              if (list)
-               continue;
+               {
+                 it_ptr->linkp = &DEPS_LIST_FIRST (list);
+                 continue;
+               }
            }
 
          *dep_ptr = NULL;

        Jakub

Reply via email to