[Core]  Fix heap overflow in LayoutPass.

Found this with asan. Code assumes that find doesn't return end, thus if
both atoms didn't have followon roots it would still compare their positions.