[libcxx-commits] [PATCH] D128285: [libc++][AIX] Make basic_string layout compatible with earlier version

Xing Xue via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 21 09:00:58 PDT 2022


xingxue created this revision.
xingxue added reviewers: ldionne, philnik, Mordante, hubert.reinterpretcast.
xingxue added a project: LLVM.
Herald added a project: All.
xingxue requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Patch D123580 <https://reviews.llvm.org/D123580> changed to use bit fields for strings in long and short mode.  As a result, this changes the layout of these strings on AIX because bit fields on AIX are 4 bytes, which breaks the ABI compatibility with earlier strings before the change on AIX.  This patch applies the fix proposed by @hubert.reinterpretcast in https://reviews.llvm.org/D127672#3590741 to make string layout compatible.  This patch will also make test cases `alignof.compile.pass.cpp` and `sizeof.compile.pass.cpp` introduced in D127672 <https://reviews.llvm.org/D127672> (later reverted) pass on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128285

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -721,24 +721,34 @@
     static const size_type __endian_factor = 2;
 #endif
 
-    struct __long
+_LIBCPP_PACKED_BYTE_FOR_AIX
+    struct __long_impl
     {
         size_type __is_long_ : 1;
         size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
         size_type __size_;
+        char
+            __padding_[sizeof(pointer) *
+                           ((2 * sizeof(size_type) - 1) / sizeof(pointer) + 1) -
+                       2 * sizeof(size_type)];
         pointer   __data_;
     };
+_LIBCPP_PACKED_BYTE_FOR_AIX_END
+    struct alignas(size_type) alignas(pointer) __long : __long_impl {};
 
     enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
                       (sizeof(__long) - 1)/sizeof(value_type) : 2};
 
-    struct __short
+_LIBCPP_PACKED_BYTE_FOR_AIX
+    struct __short_impl
     {
         unsigned char __is_long_ : 1;
         unsigned char __size_ : 7;
         char __padding_[sizeof(value_type) - 1];
         value_type __data_[__min_cap];
     };
+_LIBCPP_PACKED_BYTE_FOR_AIX_END
+    struct alignas(value_type) __short : __short_impl {};
 
 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128285.438713.patch
Type: text/x-patch
Size: 1301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220621/82199d39/attachment.bin>


More information about the libcxx-commits mailing list