[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)
Pengcheng Wang via cfe-commits
cfe-commits at lists.llvm.org
Wed May 22 20:04:18 PDT 2024
wangpc-pp wrote:
> This one is broken https://lab.llvm.org/buildbot/#/builders/168/builds/20461
The broken case is:
```cpp
void test_allocate_deallocate() {
std::pmr::memory_resource& r1 = *std::pmr::new_delete_resource();
globalMemCounter.reset();
void* ret = r1.allocate(50);
assert(ret);
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkOutstandingNewEq(1));
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkLastNewSizeEq(50));
r1.deallocate(ret, 1);
assert(globalMemCounter.checkOutstandingNewEq(0));
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(1));
}
```
The errors are:
```
# .---command stderr------------
# | =================================================================
# | ==3452201==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x506000000020 in thread T0:
# | object passed to delete has wrong type:
# | size of the allocated type: 50 bytes;
# | size of the deallocated type: 1 bytes.
# | #0 0x565094abbd02 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14ad02)
# | #1 0x565094abe168 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14d168)
# | #2 0x565094abd941 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14c941)
# | #3 0x565094abda24 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14ca24)
# | #4 0x7f8643c2814f (/lib/x86_64-linux-gnu/libc.so.6+0x2814f) (BuildId: b20cbdb62d7717c13dc61a48b7b2e673a7edf233)
# | #5 0x7f8643c28208 (/lib/x86_64-linux-gnu/libc.so.6+0x28208) (BuildId: b20cbdb62d7717c13dc61a48b7b2e673a7edf233)
# | #6 0x5650949dbed4 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x6aed4)
# |
# | 0x506000000020 is located 0 bytes inside of 50-byte region [0x506000000020,0x506000000052)
# | allocated by thread T0 here:
# | #0 0x565094abb09d (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14a09d)
# | #1 0x565094abe098 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14d098)
# | #2 0x565094abd83f (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14c83f)
# | #3 0x565094abda24 (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14ca24)
# | #4 0x7f8643c2814f (/lib/x86_64-linux-gnu/libc.so.6+0x2814f) (BuildId: b20cbdb62d7717c13dc61a48b7b2e673a7edf233)
# |
# | SUMMARY: AddressSanitizer: new-delete-type-mismatch (/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/test/std/utilities/utility/mem.res/mem.res.global/Output/new_delete_resource.pass.cpp.dir/t.tmp.exe+0x14ad02)
# | ==3452201==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
# | ==3452201==ABORTING
# `-----------------------------
# error: command failed with exit status: 1
```
Based on my rough understanding, this is expected? Because we allocate 50 bytes via `void* ret = r1.allocate(50);` and deallocate 1 byte via `r1.deallocate(ret, 1);`.
https://github.com/llvm/llvm-project/pull/90373
More information about the cfe-commits
mailing list