[libcxx-commits] [PATCH] D125496: [libc++] Simplify the string structures a bit more

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 12 12:43:46 PDT 2022


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

This simplifies the string structs a bit more and the normal layout should not contain any undefined behaviour anymore. I don't think there is a way to achieve this in the alternate string mode without breaking the ABI.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125496

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -689,14 +689,13 @@
     struct __short
     {
         value_type __data_[__min_cap];
-        unsigned char __padding[sizeof(value_type) - 1];
-        unsigned char __size_ : 7;
-        unsigned char __is_long_ : 1;
+        unsigned char __padding_[sizeof(value_type) - 1];
+        size_type __size_ : 7;
+        size_type __is_long_ : 1;
     };
 
 // The __endian_factor is required because the field we use to store the size
-// (either size_type or unsigned char depending on long/short) has one fewer
-// bit than it would if it were not a bitfield.
+// has one fewer bit than it would if it were not a bitfield.
 //
 // If the LSB is used to store the short-flag in the short string representation,
 // we have to multiply the size by two when it is stored and divide it by two when
@@ -735,14 +734,9 @@
 
     struct __short
     {
-        union
-        {
-            struct {
-                unsigned char __is_long_ : 1;
-                unsigned char __size_ : 7;
-            };
-            value_type __lx;
-        };
+        size_type __is_long_ : 1;
+        size_type __size_ : 7;
+        char __padding_[sizeof(value_type) - 1];
         value_type __data_[__min_cap];
     };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125496.429050.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220512/b979e40e/attachment.bin>


More information about the libcxx-commits mailing list