[libcxx-commits] [libcxx] 0d108f7 - [libc++] Use unsigned char in basic_string::__short again

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 12 12:06:52 PDT 2022


Author: Nikolas Klauser
Date: 2022-06-12T21:06:46+02:00
New Revision: 0d108f7908586efe2d550fed10ba21b4ea69836e

URL: https://github.com/llvm/llvm-project/commit/0d108f7908586efe2d550fed10ba21b4ea69836e
DIFF: https://github.com/llvm/llvm-project/commit/0d108f7908586efe2d550fed10ba21b4ea69836e.diff

LOG: [libc++] Use unsigned char in basic_string::__short again

D125496 changed the string layout on windows. Change `__is_long_` and `__size_` back to using `unsigned char` to fix the issue.

Reviewed By: Mordante, #libc

Spies: jloser, libcxx-commits, ayzhao

Differential Revision: https://reviews.llvm.org/D127566

Added: 
    

Modified: 
    libcxx/include/string

Removed: 
    


################################################################################
diff  --git a/libcxx/include/string b/libcxx/include/string
index a5e1290441607..7229a568a2a10 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -692,8 +692,8 @@ private:
     {
         value_type __data_[__min_cap];
         unsigned char __padding_[sizeof(value_type) - 1];
-        size_type __size_ : 7;
-        size_type __is_long_ : 1;
+        unsigned char __size_ : 7;
+        unsigned char __is_long_ : 1;
     };
 
 // The __endian_factor is required because the field we use to store the size
@@ -736,14 +736,16 @@ private:
 
     struct __short
     {
-        size_type __is_long_ : 1;
-        size_type __size_ : 7;
+        unsigned char __is_long_ : 1;
+        unsigned char __size_ : 7;
         char __padding_[sizeof(value_type) - 1];
         value_type __data_[__min_cap];
     };
 
 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
+    static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size.");
+
     union __ulx{__long __lx; __short __lxx;};
 
     enum {__n_words = sizeof(__ulx) / sizeof(size_type)};


        


More information about the libcxx-commits mailing list