| Issue |
87010
|
| Summary |
clang fails to eliminate redundant bounds check from std::vector::push_back
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
efriedma-quic
|
Consider the following:
```
#include <vector>
void f1(std::vector<int>&x) { x.push_back(1);}
```
Compile with `-O2 -stdlib=libc++`, and looks at the resulting assembly. (https://godbolt.org/z/d3GzvEGY4)
There are two bounds checks on the size of the vector: the first in the implementation of std::vector itself, which checks that the length of the vector isn't too large, and calls __throw_length_error if it fails. Then, there's a check inside the allocator that the allocation isn't too large, and calls __throw_bad_array_new_length if it fails. But the second check shouldn't be necessary: if the vector isn't too large, the allocation also isn't too large, since "too large" is defined exactly the same way for both checks.
(Briefly discussed in #64132, but I'm breaking it out into its own issue for clarity.)
CC @fhahn @hiraditya @philnik777
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs