This is an archive of the discontinued LLVM Phabricator instance.

[asan] Adhere to AddressSanitizer's alignment requirements for the end of a region.
Needs ReviewPublic

Authored by bobsayshilol on Feb 5 2020, 7:07 PM.

Details

Summary

vector<> is only annotated if the allocator it's using matches the default allocator, however client code can override the global operator new() and operator delete() which then controls how the default allocator behaves. If the allocation returned by these overridden operators doesn't come from the heap then AddressSanitizer requires that both the start and end be aligned to 8B. The start will always be aligned to at least 8B because the global operator new() doesn't know the type it's allocating for and therefore must match the natural alignment, however the end may not be aligned to 8B if the size of the allocation isn't a multiple of 8B.

This patch fixes the issue by rounding up the capacity of a vector<> on resize to a size that satisfies AddressSanitizer's requirements.

Diff Detail

Event Timeline

bobsayshilol created this revision.Feb 5 2020, 7:07 PM
mclow.lists added inline comments.Feb 5 2020, 7:32 PM
libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp
27

shrink_to_fit cannot increase capacity.

  • Fix backwards asserts that must have gotten trampled when reformatting.
  • Add another resizing test by inserting elements into the middle of the vector<>.
  • Remove TEST_STD_VER check in favour of UNSUPPORTED. The behaviour isn't specific to C++11 and above, but I don't know how to write parts of the test in a pre-C++11 way.
  • Be explicit about the capacities in shrink_to_fit.pass.cpp when AddressSanitizer is enabled.
  • Exclude a test that will no longer work if AddressSanitizer is enabled without exceptions in shrink_to_fit.pass.cpp.
bobsayshilol marked 2 inline comments as done.Feb 6 2020, 3:23 PM
bobsayshilol added inline comments.
libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp
27

I've updated the patch to be explicit about the capacity after all calls to shrink_to_fit(). It looks like I managed to miss a handful of other things when I initially submitted the patch but the new patch should fix those up too.

bobsayshilol marked an inline comment as done.Feb 17 2020, 2:48 PM

Forgot to mark this comment as done when I updated the patch.