-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Use correct size for deallocation of arrays in shared_ptr (#…
…68233) Fixes #68051. Current implementation passes the number of `_AlignedStorage` objects when it calls to `allocate` and the number of **bytes** on `deallocate`. This only applies to allocations that allocate control block and the storage together, i.e. `make_shared` and `allocate_shared`. Found by ASan under Clang combined with `-fsized-deallocation`. (cherry picked from commit f722db02d359e29ca001b78197ee1a275f8c3d7c)
- Loading branch information
1 parent
e6de86c
commit b5cbb35
Showing
2 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
// REQUIRES: -fsized-deallocation | ||
// ADDITIONAL_COMPILE_FLAGS: -fsized-deallocation | ||
|
||
// This test will fail with ASan if the implementation passes different sizes | ||
// to corresponding allocation and deallocation functions. | ||
|
||
#include <memory> | ||
|
||
int main(int, char**) { | ||
std::allocate_shared<int[]>(std::allocator<int>{}, 10); | ||
std::make_shared<int[]>(10); | ||
|
||
std::allocate_shared<int[10]>(std::allocator<int>{}); | ||
std::make_shared<int[10]>(); | ||
|
||
return 0; | ||
} |