https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85563

--- Comment #13 from eggert at cs dot ucla.edu ---
(In reply to Jakub Jelinek from comment #10)

> I don't understand that.  You had:
>   ((CONSP (Vframe_list)) ? (void) 0 : __builtin_unreachable ());
>   for ((tail) = Vframe_list; (CONSP (tail) && (frame1 = XCAR (tail), 1));
> tail = XCDR (tail))
>     body...;
> so, the assertion is testing what the CONSP will test on the first iteration.
> So, if Qnil fails CONSP test, then it would fail the assertion, if it
> doesn't, then the first iteration is done unconditionally.

You're right, and sorry about the confusion; I didn't read your earlier message
correctly.

However, the solution that you propose won't work well for Emacs, because the
code is packaged up in this macro:

#define FOR_EACH_FRAME(list_var, frame_var)     \
  for ((list_var) = Vframe_list;                \
       (CONSP (list_var)                        \
        && (frame_var = XCAR (list_var), true)); \
       list_var = XCDR (list_var))

where the macro call is the head of a for-loop, like this:

  FOR_EACH_FRAME (tail, f)
    {
      if (EQ (frame, f) && !NILP (prev))
        return prev;
      f = candidate_frame (f, frame, minibuf);
      if (!NILP (f))
        prev = f;
    }

Although I could replace the macro with its definiens and then rewrite that as
you suggest, the result would be quite a bit harder to follow; and I can't
rewrite FOR_EACH_FRAME to use a while loop preceded by some other stuff, as
that would break the expectation of the macro caller that 'FOR_EACH_FRAME (x,
y) STMT' is a single C statement.

Reply via email to