This really only hits for bitsets with a size of a multiple of 32. We
can end up with pos = -1 as a result of the ffs, which we in turn decide
is a valid position (since we fall through the loop and i == 1, we end
up adding 32 to it, so end up returning 31 again).
Up until recently this was largely unreachable, as the register file
sizes were all 63 or 255. However with the advent of compute shaders
which can restrict the number of registers, this can now happen.
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: "12.0" <mesa-stable@lists.freedesktop.org>
}
}
}
+
+ // If we couldn't find a position, we can have a left-over -1 in pos. Make
+ // sure to abort in such a case.
+ if (pos < 0)
+ return -1;
+
pos += i * 32;
return ((pos + count) <= size) ? pos : -1;