[llvm] [LLVM][ADT] Explicitly convert size_t values to SmallVector's size type (PR #77939)
Andrei Golubev via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 15 02:58:38 PST 2024
================
@@ -99,8 +99,9 @@ template <class Size_T> class SmallVectorBase {
///
/// This does not construct or destroy any elements in the vector.
void set_size(size_t N) {
- assert(N <= capacity());
- Size = N;
+ auto n = static_cast<Size_T>(N);
+ assert(n <= capacity());
----------------
andrey-golubev wrote:
> capacity() also returns size_t, so probably better to keep the assertion first.
good point. I'm not sure why our downstream had it differently. "reverted" this part back.
overall, rewrote this part as per @browneee 's advice. I think it makes sense to keep the `assert(static_cast<size_t>(Size) == N);` at the end as well. if anything, it's a function's postcondition validation so should be no harm (also, wondering if it might actually catch any data-losing `size_t -> uint32_t` narrowings).
https://github.com/llvm/llvm-project/pull/77939
More information about the llvm-commits
mailing list