Skip to content

Conversation

@philnik777
Copy link
Contributor

This breaks the ABI of flat_{,multi}map::value_compare, but this type has only been introduced in LLVM 20, so it should be very unlikely that we break anybody if we back-port this now.

@philnik777 philnik777 requested a review from a team as a code owner April 28, 2025 08:26
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Apr 28, 2025
@philnik777 philnik777 changed the title [libc++] Add _LIBCPP_NO_UNIQUE_ADDRESS to {,multi}_map::value_compare [libc++] Add _LIBCPP_NO_UNIQUE_ADDRESS to flat_{,multi}map::value_compare Apr 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

This breaks the ABI of flat_{,multi}map::value_compare, but this type has only been introduced in LLVM 20, so it should be very unlikely that we break anybody if we back-port this now.


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

2 Files Affected:

  • (modified) libcxx/include/__flat_map/flat_map.h (+1-1)
  • (modified) libcxx/include/__flat_map/flat_multimap.h (+1-1)
diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index f5abfd0985280..f5e9756ff6a60 100644
--- a/libcxx/include/__flat_map/flat_map.h
+++ b/libcxx/include/__flat_map/flat_map.h
@@ -114,7 +114,7 @@ class flat_map {
 
   class value_compare {
   private:
-    key_compare __comp_;
+    _LIBCPP_NO_UNIQUE_ADDRESS key_compare __comp_;
     _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
     friend flat_map;
 
diff --git a/libcxx/include/__flat_map/flat_multimap.h b/libcxx/include/__flat_map/flat_multimap.h
index ea77fb5d79bd2..15fcd7995ad0a 100644
--- a/libcxx/include/__flat_map/flat_multimap.h
+++ b/libcxx/include/__flat_map/flat_multimap.h
@@ -115,7 +115,7 @@ class flat_multimap {
 
   class value_compare {
   private:
-    key_compare __comp_;
+    _LIBCPP_NO_UNIQUE_ADDRESS key_compare __comp_;
     _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
     friend flat_multimap;
 

Copy link
Member

@huixie90 huixie90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is very unlikely to break anything, because value_compare is not stored in flat_map. The only situation this can break anything is when user do m.value_compare() and then store the results in a struct.

Could we add a unittest in libcxx folder?

Otherwise LGTM

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is very low risk if we do it right now and backport it. I also don't see what test we'd add for this in order to really add value. LGTM as is.

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status May 7, 2025
@ldionne ldionne merged commit ed0aa99 into llvm:main May 7, 2025
87 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status May 7, 2025
@ldionne
Copy link
Member

ldionne commented May 7, 2025

/cherry-pick ed0aa99

@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

/pull-request #138880

alexrp added a commit to alexrp/zig that referenced this pull request May 9, 2025
alexrp added a commit to ziglang/zig that referenced this pull request May 10, 2025
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Jun 12, 2025
…pare (llvm#137594)

This breaks the ABI of `flat_{,multi}map::value_compare`, but this type
has only been introduced in LLVM 20, so it should be very unlikely that
we break anybody if we back-port this now.

(cherry picked from commit ed0aa99)
dasimmet pushed a commit to dasimmet/zig that referenced this pull request Aug 4, 2025
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.

Projects

Development

Successfully merging this pull request may close these issues.

5 participants