[PATCH] D93532: [ADT] Add resize_for_overwrite method to SmallVector.
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 19 12:04:43 PST 2020
dblaikie added a comment.
In D93532#2464225 <https://reviews.llvm.org/D93532#2464225>, @dexonsmith wrote:
> In D93532#2463995 <https://reviews.llvm.org/D93532#2463995>, @njames93 wrote:
>
>> In D93532#2463881 <https://reviews.llvm.org/D93532#2463881>, @dexonsmith wrote:
>>
>>> I wonder if this can be tested, something like:
>>>
>>> V.push_back(5);
>>> V.pop_back();
>>> V.resize_for_overwrite(V.size() + 1);
>>> EXPECT_EQ(5, V.back());
>>> V.pop_back();
>>> V.resize(V.size() + 1);
>>> EXPECT_EQ(0, V.back());
>>
>> Was thinking of a good way to test what is essentially undefined behaviour, how will this work under msan??
>
> Given that we own `SmallVector` and `destroy_range` is a no-op, is it undefined behaviour?
Ish. We have used __msan_* and __asan_* functions to annotate LLVM's allocators so that uses of memory that hasn't been allocated into the pool, but not assigned to any user of the allocator can be detected (or memory used after it's returned to the allocator). We can/possibly should add such annotations to SmallVector and I think it could catch bugs like this.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93532/new/
https://reviews.llvm.org/D93532
More information about the llvm-commits
mailing list