This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Need advice on bounds checking approaches
- To: law at cygnus dot com
- Subject: Re: Need advice on bounds checking approaches
- From: Joern Rennecke <amylaar at cygnus dot co dot uk>
- Date: Tue, 28 Mar 2000 18:56:43 +0100 (BST)
- CC: Greg McGary <gkm at eng dot ascend dot com>, Geoff Keating <geoffk at cygnus dot com>, gcc at gcc dot gnu dot org
> 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.