Skip to content

[libc++] Replace __is_trivially_relocatable by is_trivially_copyable #124970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 6, 2025

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jan 29, 2025

The __is_trivially_relocatable builtin has semantics that do not correspond to any current or future notion of trivial relocation. Furthermore, it currently leads to incorrect optimizations for some types on supported compilers:

  • Clang on Windows where types with non-trivial destructors get incorrectly optimized
  • AppleClang where types with non-trivial move constructors get incorrectly optimized

Until there is an agreed upon and bugfree implementation of what it means to be trivially relocatable, it is safer to simply use trivially copyable instead. This doesn't leave a lot of types behind and is definitely correct.

@ldionne ldionne requested a review from a team as a code owner January 29, 2025 18:43
@ldionne ldionne added this to the LLVM 20.X Release milestone Jan 29, 2025
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

The __is_trivially_relocatable builtin has semantics that do not correspond to any current or future notion of trivial relocation. Furthermore, it currently leads to incorrect optimizations for some types on supported compilers:

  • Clang on Windows where types with non-trivial destructors get incorrectly optimized
  • AppleClang where types with non-trivial move constructors get incorrectly optimized

Until there is an agreed upon and bugfree implementation of what it means to be trivially relocatable, it is safer to simply use trivially copyable instead. This doesn't leave a lot of types behind and is definitely correct.


Full diff: https://github.com/llvm/llvm-project/pull/124970.diff

3 Files Affected:

  • (modified) libcxx/include/__type_traits/is_trivially_relocatable.h (-7)
  • (modified) libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp (+10)
  • (added) libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp (+67)
diff --git a/libcxx/include/__type_traits/is_trivially_relocatable.h b/libcxx/include/__type_traits/is_trivially_relocatable.h
index c0871731cc0016..ecc97a41dfbdcb 100644
--- a/libcxx/include/__type_traits/is_trivially_relocatable.h
+++ b/libcxx/include/__type_traits/is_trivially_relocatable.h
@@ -11,7 +11,6 @@
 
 #include <__config>
 #include <__type_traits/enable_if.h>
-#include <__type_traits/integral_constant.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/is_trivially_copyable.h>
 
@@ -23,14 +22,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // A type is trivially relocatable if a move construct + destroy of the original object is equivalent to
 // `memcpy(dst, src, sizeof(T))`.
-
-#if __has_builtin(__is_trivially_relocatable)
-template <class _Tp, class = void>
-struct __libcpp_is_trivially_relocatable : integral_constant<bool, __is_trivially_relocatable(_Tp)> {};
-#else
 template <class _Tp, class = void>
 struct __libcpp_is_trivially_relocatable : is_trivially_copyable<_Tp> {};
-#endif
 
 template <class _Tp>
 struct __libcpp_is_trivially_relocatable<_Tp,
diff --git a/libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp b/libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp
index 674df1d0219057..e43f38aa26f7d0 100644
--- a/libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp
+++ b/libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp
@@ -60,6 +60,16 @@ static_assert(std::__libcpp_is_trivially_relocatable<MoveOnlyTriviallyCopyable>:
 static_assert(!std::__libcpp_is_trivially_relocatable<MoveOnlyTriviallyCopyable>::value, "");
 #endif
 
+struct NonTrivialMoveConstructor {
+  NonTrivialMoveConstructor(NonTrivialMoveConstructor&&);
+};
+static_assert(!std::__libcpp_is_trivially_relocatable<NonTrivialMoveConstructor>::value, "");
+
+struct NonTrivialDestructor {
+  ~NonTrivialDestructor() {}
+};
+static_assert(!std::__libcpp_is_trivially_relocatable<NonTrivialDestructor>::value, "");
+
 // library-internal types
 // ----------------------
 
diff --git a/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp b/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp
new file mode 100644
index 00000000000000..e109a5034032dd
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// Make sure we don't miscompile vector operations for types that shouldn't be considered
+// trivially relocatable.
+
+#include <vector>
+#include <cassert>
+#include <cstddef>
+
+#include "test_macros.h"
+
+struct Tracker {
+  std::size_t move_constructs = 0;
+};
+
+struct [[clang::trivial_abi]] Inner {
+  TEST_CONSTEXPR explicit Inner(Tracker* tracker) : tracker_(tracker) {}
+  TEST_CONSTEXPR Inner(const Inner& rhs) : tracker_(rhs.tracker_) { tracker_->move_constructs += 1; }
+  TEST_CONSTEXPR Inner(Inner&& rhs) : tracker_(rhs.tracker_) { tracker_->move_constructs += 1; }
+  Tracker* tracker_;
+};
+
+// Even though this type contains a trivial_abi type, it is not trivially move-constructible,
+// so we should not attempt to optimize its move construction + destroy using trivial relocation.
+struct NotTriviallyMovable {
+  TEST_CONSTEXPR explicit NotTriviallyMovable(Tracker* tracker) : inner_(tracker) {}
+  TEST_CONSTEXPR NotTriviallyMovable(NotTriviallyMovable&& other) : inner_(std::move(other.inner_)) {}
+  Inner inner_;
+};
+static_assert(!std::is_trivially_copyable<NotTriviallyMovable>::value, "");
+LIBCPP_STATIC_ASSERT(!std::__libcpp_is_trivially_relocatable<NotTriviallyMovable>::value, "");
+
+TEST_CONSTEXPR_CXX20 bool tests() {
+  Tracker track;
+  std::vector<NotTriviallyMovable> v;
+
+  // Fill the vector at its capacity, such that any subsequent push_back would require growing.
+  v.reserve(5);
+  for (std::size_t i = 0; i != 5; ++i) {
+    v.emplace_back(&track);
+  }
+  assert(track.move_constructs == 0);
+  assert(v.size() == 5);
+
+  // Force a reallocation of the buffer + relocalization of the elements.
+  // All the existing elements of the vector should be move-constructed to their new location.
+  v.emplace_back(&track);
+  assert(track.move_constructs == 5);
+
+  return true;
+}
+
+int main(int, char**) {
+  tests();
+#if TEST_STD_VER >= 20
+  static_assert(tests());
+#endif
+  return 0;
+}

The __is_trivially_relocatable builtin has semantics that do not
correspond to any current or future notion of trivial relocation.
Furthermore, it currently leads to incorrect optimizations for some
types on supported compilers:
- Clang on Windows where types with non-trivial destructors get
  incorrectly optimized
- AppleClang where types with non-trivial move constructors get
  incorrectly optimized

Until there is an agreed upon and bugfree implementation of what it
means to be trivially relocatable, it is safer to simply use trivially
copyable instead. This doesn't leave a lot of types behind and is
definitely correct.
@ldionne ldionne force-pushed the review/stop-using-trivially-relocatable branch from e39266e to 55eaf47 Compare February 4, 2025 19:45
@ldionne ldionne added the pending-ci Merging the PR is only pending completion of CI label Feb 5, 2025
@ldionne ldionne merged commit accfbd4 into llvm:main Feb 6, 2025
76 checks passed
@ldionne ldionne deleted the review/stop-using-trivially-relocatable branch February 6, 2025 03:32
@ldionne
Copy link
Member Author

ldionne commented Feb 6, 2025

/cherry-pick accfbd4

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

Failed to create pull request for issue124970 https://github.com/llvm/llvm-project/actions/runs/13171297029

@ldionne
Copy link
Member Author

ldionne commented Feb 6, 2025

/cherry-pick accfbd4

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

/pull-request #125996

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 8, 2025
…lvm#124970)

The __is_trivially_relocatable builtin has semantics that do not
correspond to any current or future notion of trivial relocation.
Furthermore, it currently leads to incorrect optimizations for some
types on supported compilers:
- Clang on Windows where types with non-trivial destructors get
  incorrectly optimized
- AppleClang where types with non-trivial move constructors get
  incorrectly optimized

Until there is an agreed upon and bugfree implementation of what it
means to be trivially relocatable, it is safer to simply use trivially
copyable instead. This doesn't leave a lot of types behind and is
definitely correct.

(cherry picked from commit accfbd4)
@zmodem
Copy link
Collaborator

zmodem commented Feb 11, 2025

We saw a slight binary increase from this, which I suppose was expected.

Could you add some color on why this change was made now, and what were the incorrect optimizations. I guess some destructors which were supposed to run didn't?

Do you think we'll be able to get this back in some form later?

aarongable pushed a commit to chromium/chromium that referenced this pull request Feb 11, 2025
and manually update RawPtrTest.TrivialRelocability after the upstream
vector resizing optimization for trivially relocatable types was
disabled by [1] (see crbug.com/395659810).

The same [1] change also causes minor binary size growth.

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git/+log/12150825ca73..492ff432ef34

2025-02-10 [email protected] [libc++][CI] Updates Clang HEAD version in Docker. (#126419)
2025-02-10 [email protected] [libc++] Improves type-safety in generator script. (#101880)
2025-02-09 [email protected] [libc++][doc] Updates format status.
2025-02-09 [email protected] [NFC][libc++] Fixes minor issues in the synopsis.
2025-02-08 [email protected] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
2025-02-07 [email protected] [libc++] Further refactor sequence container benchmarks (#126129)
2025-02-07 [email protected] Revert "[libc++] Reduce std::conjunction overhead (#124259)"
2025-02-07 [email protected] [libc++] Refactor strings operator+ tests
2025-02-07 [email protected] [libc++][NFC] Replace typedefs with using aliases in <string> (#126070)
2025-02-06 [email protected] [libc++] Implement generic associative container benchmarks (#123663)
2025-02-06 [email protected] [libc++][NFC] Inline the simple observer functions into the basic_string definition (#126061)
2025-02-06 [email protected] [libc++][NFC] Remove __default_allocator_type aliases (#126066)
2025-02-06 [email protected] [libc++][chrono] implements TAI clock. (#125550)
2025-02-06 [email protected] [libc++] Remove basic_string::__clear_and_shrink (#126050)
2025-02-06 [email protected] Reapply "[libc++] Simplify the implementation of reserve() and shrink_to_fit() (#113453)" (#125888)
2025-02-06 [email protected] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (#125284)
2025-02-06 [email protected] [libc++] Slightly simplify max_size and add new tests for vector (#119990)
2025-02-06 [email protected] [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970)
2025-02-05 [email protected] [lib++][Format] Updates Unicode database. (#125712)
2025-02-05 [email protected] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410)
2025-02-05 [email protected] [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839)
2025-02-05 [email protected] [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows
2025-02-04 [email protected] [libc++][TZDB] Fixes %z escaping. (#125399)
2025-02-04 [email protected] [libc++] Decrease instantiation cost of __constexpr_memmove (#125109)
2025-02-03 [email protected] [libc++] Add a benchmark for std::reverse (#125262)
2025-01-30 [email protected] [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312)
2025-01-30 [email protected] [libc++] Refactor the sequence container benchmarks (#119763)
2025-01-30 [email protected] [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026)
2025-01-30 [email protected] [libc++] Forward-proof some tests for AppleClang 17
2025-01-30 [email protected] [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013)
2025-01-30 [email protected] [libc++] Refactor num_get optimization to not be ABI breaking (#121690)
2025-01-29 [email protected] [libc++] Add clang-21 to failing tests on Windows (#124955)
2025-01-29 [email protected] [libc++] Simplify the implementation of iostream.cpp (#124103)
2025-01-29 [email protected] [libc++] Simplify vector<bool>::__construct_at_end (#119632)
2025-01-29 [email protected] [libc++] Remove some private symbols from the ABI (#121497)
2025-01-29 [email protected] [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)
2025-01-29 [email protected] Bump version to 21.0.0git (#124870)
2025-01-28 [email protected] [libc++] Disable CFI in __libcpp_allocate (#124805)
2025-01-28 [email protected] [libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)
2025-01-28 [email protected] [libc++] Remove Android header no longer in use (#124691)
2025-01-28 [email protected] Revert "[libcxx] Use alias for detecting overriden function" (#124431)
2025-01-27 [email protected] [libc++][format] Add tests for flat_(|multi)map formatting (#124418)
2025-01-27 [email protected] [libc++][doc] Update the release notes for LLVM 20. (#124403)
2025-01-27 [email protected] [libc++] Add more missing bits to the locale base API (#122531)
2025-01-25 [email protected] [libc++] implement `std::flat_multimap` (#113835)
2025-01-25 [email protected] [libc++][format][3/3] Improves formatting performance. (#108990)
2025-01-25 [email protected] [libc++][test] Improves C++ Standard filtering. (#89499)
2025-01-25 [email protected] [libc++] Reduce std::conjunction overhead (#124259)
2025-01-25 [email protected] Reapply "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-25 [email protected] Revert "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-24 [email protected] [libc++] Fix tests for clang::no_specializations for C++17 and C++20
2025-01-24 [email protected] [libc++][TZDB] Fixes CI.
2025-01-24 [email protected] [libc++][chrono] implements UTC clock. (#90393)
2025-01-24 [email protected] [libc++] Switch experimental library macros to 0/1 macros (#124030)
2025-01-23 [email protected] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
2025-01-23 [email protected] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/libcxx-chromium
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Chromium: https://bugs.chromium.org/p/chromium/issues/entry

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

  [1] llvm/llvm-project#124970

Binary-Size: Minor growth due to libc++ change, see above.
Fuchsia-Binary-Size: Same.
Bug: 392938080
Change-Id: I0299b69415020a064f999a9ac0a80ffc5ebd0bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250498
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Hans Wennborg <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1418630}
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…lvm#124970)

The __is_trivially_relocatable builtin has semantics that do not
correspond to any current or future notion of trivial relocation.
Furthermore, it currently leads to incorrect optimizations for some
types on supported compilers:
- Clang on Windows where types with non-trivial destructors get
  incorrectly optimized
- AppleClang where types with non-trivial move constructors get
  incorrectly optimized

Until there is an agreed upon and bugfree implementation of what it
means to be trivially relocatable, it is safer to simply use trivially
copyable instead. This doesn't leave a lot of types behind and is
definitely correct.
ArthurSonzogni pushed a commit to ArthurSonzogni/PartitionAlloc that referenced this pull request Feb 12, 2025
and manually update RawPtrTest.TrivialRelocability after the upstream
vector resizing optimization for trivially relocatable types was
disabled by [1] (see crbug.com/395659810).

The same [1] change also causes minor binary size growth.

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git/+log/12150825ca73..492ff432ef34

2025-02-10 [email protected] [libc++][CI] Updates Clang HEAD version in Docker. (#126419)
2025-02-10 [email protected] [libc++] Improves type-safety in generator script. (#101880)
2025-02-09 [email protected] [libc++][doc] Updates format status.
2025-02-09 [email protected] [NFC][libc++] Fixes minor issues in the synopsis.
2025-02-08 [email protected] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
2025-02-07 [email protected] [libc++] Further refactor sequence container benchmarks (#126129)
2025-02-07 [email protected] Revert "[libc++] Reduce std::conjunction overhead (#124259)"
2025-02-07 [email protected] [libc++] Refactor strings operator+ tests
2025-02-07 [email protected] [libc++][NFC] Replace typedefs with using aliases in <string> (#126070)
2025-02-06 [email protected] [libc++] Implement generic associative container benchmarks (#123663)
2025-02-06 [email protected] [libc++][NFC] Inline the simple observer functions into the basic_string definition (#126061)
2025-02-06 [email protected] [libc++][NFC] Remove __default_allocator_type aliases (#126066)
2025-02-06 [email protected] [libc++][chrono] implements TAI clock. (#125550)
2025-02-06 [email protected] [libc++] Remove basic_string::__clear_and_shrink (#126050)
2025-02-06 [email protected] Reapply "[libc++] Simplify the implementation of reserve() and shrink_to_fit() (#113453)" (#125888)
2025-02-06 [email protected] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (#125284)
2025-02-06 [email protected] [libc++] Slightly simplify max_size and add new tests for vector (#119990)
2025-02-06 [email protected] [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970)
2025-02-05 [email protected] [lib++][Format] Updates Unicode database. (#125712)
2025-02-05 [email protected] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410)
2025-02-05 [email protected] [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839)
2025-02-05 [email protected] [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows
2025-02-04 [email protected] [libc++][TZDB] Fixes %z escaping. (#125399)
2025-02-04 [email protected] [libc++] Decrease instantiation cost of __constexpr_memmove (#125109)
2025-02-03 [email protected] [libc++] Add a benchmark for std::reverse (#125262)
2025-01-30 [email protected] [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312)
2025-01-30 [email protected] [libc++] Refactor the sequence container benchmarks (#119763)
2025-01-30 [email protected] [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026)
2025-01-30 [email protected] [libc++] Forward-proof some tests for AppleClang 17
2025-01-30 [email protected] [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013)
2025-01-30 [email protected] [libc++] Refactor num_get optimization to not be ABI breaking (#121690)
2025-01-29 [email protected] [libc++] Add clang-21 to failing tests on Windows (#124955)
2025-01-29 [email protected] [libc++] Simplify the implementation of iostream.cpp (#124103)
2025-01-29 [email protected] [libc++] Simplify vector<bool>::__construct_at_end (#119632)
2025-01-29 [email protected] [libc++] Remove some private symbols from the ABI (#121497)
2025-01-29 [email protected] [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)
2025-01-29 [email protected] Bump version to 21.0.0git (#124870)
2025-01-28 [email protected] [libc++] Disable CFI in __libcpp_allocate (#124805)
2025-01-28 [email protected] [libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)
2025-01-28 [email protected] [libc++] Remove Android header no longer in use (#124691)
2025-01-28 [email protected] Revert "[libcxx] Use alias for detecting overriden function" (#124431)
2025-01-27 [email protected] [libc++][format] Add tests for flat_(|multi)map formatting (#124418)
2025-01-27 [email protected] [libc++][doc] Update the release notes for LLVM 20. (#124403)
2025-01-27 [email protected] [libc++] Add more missing bits to the locale base API (#122531)
2025-01-25 [email protected] [libc++] implement `std::flat_multimap` (#113835)
2025-01-25 [email protected] [libc++][format][3/3] Improves formatting performance. (#108990)
2025-01-25 [email protected] [libc++][test] Improves C++ Standard filtering. (#89499)
2025-01-25 [email protected] [libc++] Reduce std::conjunction overhead (#124259)
2025-01-25 [email protected] Reapply "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-25 [email protected] Revert "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-24 [email protected] [libc++] Fix tests for clang::no_specializations for C++17 and C++20
2025-01-24 [email protected] [libc++][TZDB] Fixes CI.
2025-01-24 [email protected] [libc++][chrono] implements UTC clock. (#90393)
2025-01-24 [email protected] [libc++] Switch experimental library macros to 0/1 macros (#124030)
2025-01-23 [email protected] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
2025-01-23 [email protected] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/libcxx-chromium
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Chromium: https://bugs.chromium.org/p/chromium/issues/entry

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

  [1] llvm/llvm-project#124970

Binary-Size: Minor growth due to libc++ change, see above.
Fuchsia-Binary-Size: Same.
Bug: 392938080
Change-Id: I0299b69415020a064f999a9ac0a80ffc5ebd0bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250498
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Hans Wennborg <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1418630}
NOKEYCHECK=True
GitOrigin-RevId: 5b06b8e557002548a44324f7283259aafaa21803
github-actions bot pushed a commit to kaidokert/chrome_base_mirror that referenced this pull request Feb 12, 2025
and manually update RawPtrTest.TrivialRelocability after the upstream
vector resizing optimization for trivially relocatable types was
disabled by [1] (see crbug.com/395659810).

The same [1] change also causes minor binary size growth.

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git/+log/12150825ca73..492ff432ef34

2025-02-10 [email protected] [libc++][CI] Updates Clang HEAD version in Docker. (#126419)
2025-02-10 [email protected] [libc++] Improves type-safety in generator script. (#101880)
2025-02-09 [email protected] [libc++][doc] Updates format status.
2025-02-09 [email protected] [NFC][libc++] Fixes minor issues in the synopsis.
2025-02-08 [email protected] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
2025-02-07 [email protected] [libc++] Further refactor sequence container benchmarks (#126129)
2025-02-07 [email protected] Revert "[libc++] Reduce std::conjunction overhead (#124259)"
2025-02-07 [email protected] [libc++] Refactor strings operator+ tests
2025-02-07 [email protected] [libc++][NFC] Replace typedefs with using aliases in <string> (#126070)
2025-02-06 [email protected] [libc++] Implement generic associative container benchmarks (#123663)
2025-02-06 [email protected] [libc++][NFC] Inline the simple observer functions into the basic_string definition (#126061)
2025-02-06 [email protected] [libc++][NFC] Remove __default_allocator_type aliases (#126066)
2025-02-06 [email protected] [libc++][chrono] implements TAI clock. (#125550)
2025-02-06 [email protected] [libc++] Remove basic_string::__clear_and_shrink (#126050)
2025-02-06 [email protected] Reapply "[libc++] Simplify the implementation of reserve() and shrink_to_fit() (#113453)" (#125888)
2025-02-06 [email protected] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (#125284)
2025-02-06 [email protected] [libc++] Slightly simplify max_size and add new tests for vector (#119990)
2025-02-06 [email protected] [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970)
2025-02-05 [email protected] [lib++][Format] Updates Unicode database. (#125712)
2025-02-05 [email protected] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410)
2025-02-05 [email protected] [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839)
2025-02-05 [email protected] [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows
2025-02-04 [email protected] [libc++][TZDB] Fixes %z escaping. (#125399)
2025-02-04 [email protected] [libc++] Decrease instantiation cost of __constexpr_memmove (#125109)
2025-02-03 [email protected] [libc++] Add a benchmark for std::reverse (#125262)
2025-01-30 [email protected] [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312)
2025-01-30 [email protected] [libc++] Refactor the sequence container benchmarks (#119763)
2025-01-30 [email protected] [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026)
2025-01-30 [email protected] [libc++] Forward-proof some tests for AppleClang 17
2025-01-30 [email protected] [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013)
2025-01-30 [email protected] [libc++] Refactor num_get optimization to not be ABI breaking (#121690)
2025-01-29 [email protected] [libc++] Add clang-21 to failing tests on Windows (#124955)
2025-01-29 [email protected] [libc++] Simplify the implementation of iostream.cpp (#124103)
2025-01-29 [email protected] [libc++] Simplify vector<bool>::__construct_at_end (#119632)
2025-01-29 [email protected] [libc++] Remove some private symbols from the ABI (#121497)
2025-01-29 [email protected] [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)
2025-01-29 [email protected] Bump version to 21.0.0git (#124870)
2025-01-28 [email protected] [libc++] Disable CFI in __libcpp_allocate (#124805)
2025-01-28 [email protected] [libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)
2025-01-28 [email protected] [libc++] Remove Android header no longer in use (#124691)
2025-01-28 [email protected] Revert "[libcxx] Use alias for detecting overriden function" (#124431)
2025-01-27 [email protected] [libc++][format] Add tests for flat_(|multi)map formatting (#124418)
2025-01-27 [email protected] [libc++][doc] Update the release notes for LLVM 20. (#124403)
2025-01-27 [email protected] [libc++] Add more missing bits to the locale base API (#122531)
2025-01-25 [email protected] [libc++] implement `std::flat_multimap` (#113835)
2025-01-25 [email protected] [libc++][format][3/3] Improves formatting performance. (#108990)
2025-01-25 [email protected] [libc++][test] Improves C++ Standard filtering. (#89499)
2025-01-25 [email protected] [libc++] Reduce std::conjunction overhead (#124259)
2025-01-25 [email protected] Reapply "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-25 [email protected] Revert "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-24 [email protected] [libc++] Fix tests for clang::no_specializations for C++17 and C++20
2025-01-24 [email protected] [libc++][TZDB] Fixes CI.
2025-01-24 [email protected] [libc++][chrono] implements UTC clock. (#90393)
2025-01-24 [email protected] [libc++] Switch experimental library macros to 0/1 macros (#124030)
2025-01-23 [email protected] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
2025-01-23 [email protected] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/libcxx-chromium
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Chromium: https://bugs.chromium.org/p/chromium/issues/entry

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

  [1] llvm/llvm-project#124970

Binary-Size: Minor growth due to libc++ change, see above.
Fuchsia-Binary-Size: Same.
Bug: 392938080
Change-Id: I0299b69415020a064f999a9ac0a80ffc5ebd0bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250498
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Hans Wennborg <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1418630}
NOKEYCHECK=True
GitOrigin-RevId: 5b06b8e557002548a44324f7283259aafaa21803
@ldionne
Copy link
Member Author

ldionne commented Feb 13, 2025

We saw a slight binary increase from this, which I suppose was expected.

I am a bit surprised about this, I didn't expect much noticeable impact, but it's definitely not impossible. If you have details on which types are now generating less optimal std::vector operations, I could investigate.

Could you add some color on why this change was made now, and what were the incorrect optimizations. I guess some destructors which were supposed to run didn't?

You can refer to the tests added by this PR: https://github.com/llvm/llvm-project/pull/124970/files#diff-55515a02488b32e9ba3c8cf44b5f5bc73c240db8e5b1a013aba93101cfb0ba21

I have been aware of this issue for a long time, maybe 6 months, but I was struggling to come up with a good test I could check-in so I punted on the issue. I recently revived this as part of resuming involvement in the trivial relocation proposals for WG21.

Since this is effectively a bug fix, I decided to backport it to LLVM 20.

Do you think we'll be able to get this back in some form later?

Yes, definitely. We are working towards a proper notion of trivial relocation and library utilities to take advantage of it in http://wg21.link/p3516 and http://wg21.link/p2786. Once the dust has settled on the approach we're taking in WG21, the hope is that the Clang builtin will be updated to mirror the Standard property and then we can switch back to it (perhaps with some opt-outs until we drop support for "broken" compilers).

@zmodem
Copy link
Collaborator

zmodem commented Feb 13, 2025

If you have details on which types are now generating less optimal std::vector operations, I could investigate.

It's a small increase spread across the binary, so it's hard to say for sure, but it's likely our raw_ptr type which has a test checking for exactly this and gets used a lot.

Do you think we'll be able to get this back in some form later?

Yes, [...]

Sounds great, we can just wait then. Thank you!

@ldionne
Copy link
Member Author

ldionne commented Feb 15, 2025

If you have details on which types are now generating less optimal std::vector operations, I could investigate.

It's a small increase spread across the binary, so it's hard to say for sure, but it's likely our raw_ptr type which has a test checking for exactly this and gets used a lot.

Ack, thanks, the link is super useful. FYI we voted trivial relocation into the working draft for C++26 this morning, so this should be coming sooner rather than later.

What we voted in is not P1144 which you seemed to be expecting, though, it's http://wg21.link/P2786. There are some differences, so you should make sure that your type is compatible with it.

jrguzman-ms pushed a commit to msft-mirror-aosp/platform.external.libchrome that referenced this pull request Feb 19, 2025
and manually update RawPtrTest.TrivialRelocability after the upstream
vector resizing optimization for trivially relocatable types was
disabled by [1] (see crbug.com/395659810).

The same [1] change also causes minor binary size growth.

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git/+log/12150825ca73..492ff432ef34

2025-02-10 [email protected] [libc++][CI] Updates Clang HEAD version in Docker. (#126419)
2025-02-10 [email protected] [libc++] Improves type-safety in generator script. (#101880)
2025-02-09 [email protected] [libc++][doc] Updates format status.
2025-02-09 [email protected] [NFC][libc++] Fixes minor issues in the synopsis.
2025-02-08 [email protected] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
2025-02-07 [email protected] [libc++] Further refactor sequence container benchmarks (#126129)
2025-02-07 [email protected] Revert "[libc++] Reduce std::conjunction overhead (#124259)"
2025-02-07 [email protected] [libc++] Refactor strings operator+ tests
2025-02-07 [email protected] [libc++][NFC] Replace typedefs with using aliases in <string> (#126070)
2025-02-06 [email protected] [libc++] Implement generic associative container benchmarks (#123663)
2025-02-06 [email protected] [libc++][NFC] Inline the simple observer functions into the basic_string definition (#126061)
2025-02-06 [email protected] [libc++][NFC] Remove __default_allocator_type aliases (#126066)
2025-02-06 [email protected] [libc++][chrono] implements TAI clock. (#125550)
2025-02-06 [email protected] [libc++] Remove basic_string::__clear_and_shrink (#126050)
2025-02-06 [email protected] Reapply "[libc++] Simplify the implementation of reserve() and shrink_to_fit() (#113453)" (#125888)
2025-02-06 [email protected] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (#125284)
2025-02-06 [email protected] [libc++] Slightly simplify max_size and add new tests for vector (#119990)
2025-02-06 [email protected] [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970)
2025-02-05 [email protected] [lib++][Format] Updates Unicode database. (#125712)
2025-02-05 [email protected] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410)
2025-02-05 [email protected] [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839)
2025-02-05 [email protected] [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows
2025-02-04 [email protected] [libc++][TZDB] Fixes %z escaping. (#125399)
2025-02-04 [email protected] [libc++] Decrease instantiation cost of __constexpr_memmove (#125109)
2025-02-03 [email protected] [libc++] Add a benchmark for std::reverse (#125262)
2025-01-30 [email protected] [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312)
2025-01-30 [email protected] [libc++] Refactor the sequence container benchmarks (#119763)
2025-01-30 [email protected] [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026)
2025-01-30 [email protected] [libc++] Forward-proof some tests for AppleClang 17
2025-01-30 [email protected] [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013)
2025-01-30 [email protected] [libc++] Refactor num_get optimization to not be ABI breaking (#121690)
2025-01-29 [email protected] [libc++] Add clang-21 to failing tests on Windows (#124955)
2025-01-29 [email protected] [libc++] Simplify the implementation of iostream.cpp (#124103)
2025-01-29 [email protected] [libc++] Simplify vector<bool>::__construct_at_end (#119632)
2025-01-29 [email protected] [libc++] Remove some private symbols from the ABI (#121497)
2025-01-29 [email protected] [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)
2025-01-29 [email protected] Bump version to 21.0.0git (#124870)
2025-01-28 [email protected] [libc++] Disable CFI in __libcpp_allocate (#124805)
2025-01-28 [email protected] [libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)
2025-01-28 [email protected] [libc++] Remove Android header no longer in use (#124691)
2025-01-28 [email protected] Revert "[libcxx] Use alias for detecting overriden function" (#124431)
2025-01-27 [email protected] [libc++][format] Add tests for flat_(|multi)map formatting (#124418)
2025-01-27 [email protected] [libc++][doc] Update the release notes for LLVM 20. (#124403)
2025-01-27 [email protected] [libc++] Add more missing bits to the locale base API (#122531)
2025-01-25 [email protected] [libc++] implement `std::flat_multimap` (#113835)
2025-01-25 [email protected] [libc++][format][3/3] Improves formatting performance. (#108990)
2025-01-25 [email protected] [libc++][test] Improves C++ Standard filtering. (#89499)
2025-01-25 [email protected] [libc++] Reduce std::conjunction overhead (#124259)
2025-01-25 [email protected] Reapply "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-25 [email protected] Revert "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-24 [email protected] [libc++] Fix tests for clang::no_specializations for C++17 and C++20
2025-01-24 [email protected] [libc++][TZDB] Fixes CI.
2025-01-24 [email protected] [libc++][chrono] implements UTC clock. (#90393)
2025-01-24 [email protected] [libc++] Switch experimental library macros to 0/1 macros (#124030)
2025-01-23 [email protected] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
2025-01-23 [email protected] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/libcxx-chromium
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Chromium: https://bugs.chromium.org/p/chromium/issues/entry

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

  [1] llvm/llvm-project#124970

Binary-Size: Minor growth due to libc++ change, see above.
Fuchsia-Binary-Size: Same.
Bug: 392938080
Change-Id: I0299b69415020a064f999a9ac0a80ffc5ebd0bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250498
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Hans Wennborg <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1418630}


CrOS-Libchrome-Original-Commit: 5b06b8e557002548a44324f7283259aafaa21803
phuang pushed a commit to phuang/chromium_src_buildtools that referenced this pull request Apr 7, 2025
and manually update RawPtrTest.TrivialRelocability after the upstream
vector resizing optimization for trivially relocatable types was
disabled by [1] (see crbug.com/395659810).

The same [1] change also causes minor binary size growth.

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git/+log/12150825ca73..492ff432ef34

2025-02-10 [email protected] [libc++][CI] Updates Clang HEAD version in Docker. (#126419)
2025-02-10 [email protected] [libc++] Improves type-safety in generator script. (#101880)
2025-02-09 [email protected] [libc++][doc] Updates format status.
2025-02-09 [email protected] [NFC][libc++] Fixes minor issues in the synopsis.
2025-02-08 [email protected] [libc++][test] Fix `size_type` issues with `MinSequenceContainer` and `min_allocator` (#126267)
2025-02-07 [email protected] [libc++] Further refactor sequence container benchmarks (#126129)
2025-02-07 [email protected] Revert "[libc++] Reduce std::conjunction overhead (#124259)"
2025-02-07 [email protected] [libc++] Refactor strings operator+ tests
2025-02-07 [email protected] [libc++][NFC] Replace typedefs with using aliases in <string> (#126070)
2025-02-06 [email protected] [libc++] Implement generic associative container benchmarks (#123663)
2025-02-06 [email protected] [libc++][NFC] Inline the simple observer functions into the basic_string definition (#126061)
2025-02-06 [email protected] [libc++][NFC] Remove __default_allocator_type aliases (#126066)
2025-02-06 [email protected] [libc++][chrono] implements TAI clock. (#125550)
2025-02-06 [email protected] [libc++] Remove basic_string::__clear_and_shrink (#126050)
2025-02-06 [email protected] Reapply "[libc++] Simplify the implementation of reserve() and shrink_to_fit() (#113453)" (#125888)
2025-02-06 [email protected] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (#125284)
2025-02-06 [email protected] [libc++] Slightly simplify max_size and add new tests for vector (#119990)
2025-02-06 [email protected] [libc++] Replace __is_trivially_relocatable by is_trivially_copyable (#124970)
2025-02-05 [email protected] [lib++][Format] Updates Unicode database. (#125712)
2025-02-05 [email protected] [libc++] Fix UB in bitwise logic of {std, ranges}::{fill, fill_n} algorithms (#122410)
2025-02-05 [email protected] [libc++] Also provide an alignment assumption for vector in C++03 mode (#124839)
2025-02-05 [email protected] [libc++] Fix stray usage of _LIBCPP_HAS_NO_WIDE_CHARACTERS on Windows
2025-02-04 [email protected] [libc++][TZDB] Fixes %z escaping. (#125399)
2025-02-04 [email protected] [libc++] Decrease instantiation cost of __constexpr_memmove (#125109)
2025-02-03 [email protected] [libc++] Add a benchmark for std::reverse (#125262)
2025-01-30 [email protected] [libc++] Implement N4258(Cleaning-up noexcept in the Library) (#120312)
2025-01-30 [email protected] [libc++] Refactor the sequence container benchmarks (#119763)
2025-01-30 [email protected] [libc++] Optimize ranges::copy_backward for vector<bool>::iterator (#121026)
2025-01-30 [email protected] [libc++] Forward-proof some tests for AppleClang 17
2025-01-30 [email protected] [libc++] Optimize ranges::copy{, _n} for vector<bool>::iterator (#121013)
2025-01-30 [email protected] [libc++] Refactor num_get optimization to not be ABI breaking (#121690)
2025-01-29 [email protected] [libc++] Add clang-21 to failing tests on Windows (#124955)
2025-01-29 [email protected] [libc++] Simplify the implementation of iostream.cpp (#124103)
2025-01-29 [email protected] [libc++] Simplify vector<bool>::__construct_at_end (#119632)
2025-01-29 [email protected] [libc++] Remove some private symbols from the ABI (#121497)
2025-01-29 [email protected] [libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)
2025-01-29 [email protected] Bump version to 21.0.0git (#124870)
2025-01-28 [email protected] [libc++] Disable CFI in __libcpp_allocate (#124805)
2025-01-28 [email protected] [libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)
2025-01-28 [email protected] [libc++] Remove Android header no longer in use (#124691)
2025-01-28 [email protected] Revert "[libcxx] Use alias for detecting overriden function" (#124431)
2025-01-27 [email protected] [libc++][format] Add tests for flat_(|multi)map formatting (#124418)
2025-01-27 [email protected] [libc++][doc] Update the release notes for LLVM 20. (#124403)
2025-01-27 [email protected] [libc++] Add more missing bits to the locale base API (#122531)
2025-01-25 [email protected] [libc++] implement `std::flat_multimap` (#113835)
2025-01-25 [email protected] [libc++][format][3/3] Improves formatting performance. (#108990)
2025-01-25 [email protected] [libc++][test] Improves C++ Standard filtering. (#89499)
2025-01-25 [email protected] [libc++] Reduce std::conjunction overhead (#124259)
2025-01-25 [email protected] Reapply "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-25 [email protected] Revert "[libc++] Fix tests for clang::no_specializations for C++17 and C++20"
2025-01-24 [email protected] [libc++] Fix tests for clang::no_specializations for C++17 and C++20
2025-01-24 [email protected] [libc++][TZDB] Fixes CI.
2025-01-24 [email protected] [libc++][chrono] implements UTC clock. (#90393)
2025-01-24 [email protected] [libc++] Switch experimental library macros to 0/1 macros (#124030)
2025-01-23 [email protected] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
2025-01-23 [email protected] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (#118167)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/libcxx-chromium
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Chromium: https://bugs.chromium.org/p/chromium/issues/entry

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

  [1] llvm/llvm-project#124970

Binary-Size: Minor growth due to libc++ change, see above.
Fuchsia-Binary-Size: Same.
Bug: 392938080
Change-Id: I0299b69415020a064f999a9ac0a80ffc5ebd0bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250498
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Hans Wennborg <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1418630}
NOKEYCHECK=True
GitOrigin-RevId: 5b06b8e557002548a44324f7283259aafaa21803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. pending-ci Merging the PR is only pending completion of CI
Projects
Development

Successfully merging this pull request may close these issues.

4 participants