[libcxx-commits] [libcxx] [libc++][hardening] Check bounds on arithmetic in __bounded_iter (PR #78876)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 9 11:11:09 PST 2024
https://github.com/ldionne commented:
I just spoke with @var-const and this approach is growing on me more and more. I was uneasy about relying on "implicit" optimization hints at first, but the more I look at it the more it seems that these can actually become explicit optimization hints.
So let's say we have
```c++
template <random_access_iterator Iterator>
void algorithm(Iterator it, size_t n) {
(void)it + n;
// do something real
}
```
Without any hardening, we are basically telling the compiler (quite explicitly) that we expect `it + n` to be valid, and that it can assume that because otherwise we just invoked UB. With hardening, this is still true except that in addition we now validate that the assumption holds. I find this approach to be nice, generic and explicit, and I like it a lot.
I'd like @var-const to give a thumbs up too before this ships, but this LGTM with a few comments.
https://github.com/llvm/llvm-project/pull/78876
More information about the libcxx-commits
mailing list