[libcxx-commits] [PATCH] D63744: In the libc++ unstable ABI, use [[no_unique_address]] instead of __compressed_pair when available.
    James Y Knight via Phabricator via libcxx-commits 
    libcxx-commits at lists.llvm.org
       
    Mon Nov  2 14:59:13 PST 2020
    
    
  
jyknight added a comment.
In D63744#2369637 <https://reviews.llvm.org/D63744#2369637>, @ldionne wrote:
> If we assume that the compiler supports `[[no_unique_address]]`, is this an ABI break? Does `no_unique_address` result in a different layout than the `__compressed_pair`?
Yes, this creates an incompatible memory layout. I don't think there's any way around that, while getting the benefits of removing the intermediate object.
If we put [[no_unique_address]] on the elements inside __compressed_pair, I believe that probably creates the same memory layout, but that doesn't get the desired benefit.
As soon as you move the fields out of the intermediate object, you will lose some padding, and thus the layout will be different (consider `class Foo {__compressed_pair<double, char> a; __compressed_pair<short, char> b;}; ` -- due to alignment, "a" has 7 bytes of padding on the end, resulting in a 24-byte object. Whereas, with `class Foo {double a1; char a2; short b1; char b2; };` the total size of the object would only be 16 bytes. (I've omitted no_unique_address for brevity here, since none of the objects in this example are empty or possibly-empty).
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63744/new/
https://reviews.llvm.org/D63744
    
    
More information about the libcxx-commits
mailing list