Need advice on bounds checking approaches
Joern Rennecke
amylaar@cygnus.co.uk
Tue Mar 28 09:57:00 GMT 2000
> I hadn't thought of that. It assumes you can't overflow, but that's
> probably a reasonable simplification for pointer operations.
If bounds checking is wanted, I don't think it is reasonable to assume
that there can't be an overflow - after all, the point of bounds checking
is to detect bugs.
However, in most cases we will be able to deduct that there can't be an
overflow. That is:
- if a bounds check is done in every iteration, and
- if sum of the upper bound (rounded down for alignment if a STRICT_ALIGNMENT
memory access is done at every iteration), plus the increment (or the
upper bound of the value range of the increment if variable, but in a
known range) doesn't overflow.
>
> Is there any advantage to not always emitting the high/low bounds checks
> separately?
Yes, a combined check is simpler. Even if you don't have a specific
instruction for a bounds check, you can subtract the lower bound, then
compare the upper bound minus the lower bound unsigned to the subtraction
result.
More information about the Gcc
mailing list