PR 16899: Do not modify the basic block using the iterator, but keep the
next value. This avoids crashes due to invalidation.

Patch by Joey Gouly.