This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Need advice on bounds checking approaches


> 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]