diff options
author | Xing Xue <xingxue@outlook.com> | 2022-06-24 17:25:15 -0400 |
---|---|---|
committer | Xing Xue <xingxue@outlook.com> | 2022-06-24 17:25:15 -0400 |
commit | 60f7bdfd0317cb38eda54637cdab9baed8ae2f57 (patch) | |
tree | 469fca5116bea2bec1729e68d577b41cec026e43 | |
parent | 00e9d53453abc8f2e3d69e9c7fba83dc65a74259 (diff) | |
download | llvm-60f7bdfd0317cb38eda54637cdab9baed8ae2f57.zip llvm-60f7bdfd0317cb38eda54637cdab9baed8ae2f57.tar.gz llvm-60f7bdfd0317cb38eda54637cdab9baed8ae2f57.tar.bz2 |
[libc++][AIX] Make basic_string layout compatible with earlier version
Summary:
Patch 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 uses the attribute 'packed' and anonymous structure to make string layout compatible. This patch will also make test cases alignof.compile.pass.cpp and sizeof.compile.pass.cpp introduced in D127672 pass on AIX.
Reviewed by: philnik, Mordante, hubert.reinterpretcast, libc++
Differential Revision: https://reviews.llvm.org/D128285
-rw-r--r-- | libcxx/include/__config | 6 | ||||
-rw-r--r-- | libcxx/include/string | 16 |
2 files changed, 18 insertions, 4 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config index 11f934c..90ae511 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1176,6 +1176,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ # endif +# if __has_attribute(__packed__) +# define _LIBCPP_PACKED __attribute__((__packed__)) +# else +# define _LIBCPP_PACKED +# endif + #endif // __cplusplus #endif // _LIBCPP___CONFIG diff --git a/libcxx/include/string b/libcxx/include/string index ab8d2ac..0ce8c4f 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -721,10 +721,16 @@ private: static const size_type __endian_factor = 2; #endif + // Attribute 'packed' is used to keep the layout compatible with the + // previous definition that did not use bit fields. This is because on + // some platforms bit fields have a default size rather than the actual + // size used, e.g., it is 4 bytes on AIX. See D128285 for details. struct __long { - size_type __is_long_ : 1; - size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; + struct _LIBCPP_PACKED { + size_type __is_long_ : 1; + size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; + }; size_type __size_; pointer __data_; }; @@ -734,8 +740,10 @@ private: struct __short { - unsigned char __is_long_ : 1; - unsigned char __size_ : 7; + struct _LIBCPP_PACKED { + unsigned char __is_long_ : 1; + unsigned char __size_ : 7; + }; char __padding_[sizeof(value_type) - 1]; value_type __data_[__min_cap]; }; |