forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unconditionally lower std::string's alignment requirement from 16 to 8.
As requested in llvm#68807
- Loading branch information
Showing
4 changed files
with
40 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
31 changes: 31 additions & 0 deletions
31
libcxx/test/libcxx/strings/basic.string/string.capacity/allocation_size.pass.cpp
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,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <string> | ||
|
||
// This test demonstrates the smaller allocation sizes when the alignment | ||
// requirements of std::string are dropped from 16 to 8. | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstddef> | ||
#include <string> | ||
|
||
#include "test_macros.h" | ||
|
||
int main(int, char**) { | ||
std::string input_string; | ||
input_string.resize(64, 'a'); | ||
|
||
// Call a constructor which selects its size using __recommend. | ||
std::string test_string(input_string.data()); | ||
constexpr std::size_t expected_align8_size = 71; | ||
// Previously, when the alignment used to be 16 bytes, the expected | ||
// capacity was 79. | ||
assert(test_string.capacity() == expected_align8_size); | ||
} |
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