Skip to content

Commit

Permalink
[lldb][test] TestDataFormatterLibcxxStringSimulator.py: fix padding f…
Browse files Browse the repository at this point in the history
…or current layout (llvm#108362)

IIUC, the history of `std::string`'s `__short` structure in the
alternate ABI layout (as recorded by the simulator test) looks as
follows:
* First layout ( `SUBCLASS_PADDING` is defined):
```
     struct __short                                          
     {                                                       
         value_type __data_[__min_cap];                      
        struct                                              
            : __padding<value_type>                         
        {                                                   
            unsigned char __size_;                          
        };
     };                                      
```
* Then:
```
     struct __short                                         
     {                                                      
        value_type __data_[__min_cap];                                                               
        unsigned char __padding[sizeof(value_type) - 1];   
        unsigned char __size_;                             
     };
```
* Then, post-`BITMASKS`:
```
     struct __short                                         
     {                                                      
        value_type __data_[__min_cap];                                                               
        unsigned char __padding[sizeof(value_type) - 1];   
        unsigned char __size_ : 7;
        unsigned char __is_long_ : 1;                             
     };
```

Which is the one that's [on
top-of-tree](https://github.com/llvm/llvm-project/blob/89c10e27d8b4d5f44998aad9abd2590d9f96c5df/libcxx/include/string#L854-L859).

But for `REVISION > 1`, `BITMASKS` is never set, so for those tests we
lose the `__padding` member.

This patch fixes this by splitting out the `SUBCLASS_PADDING` out of the
ifdef.

Drive-by:
* Also run expression evaluator on the string to provide is with some
extra coverage.
  • Loading branch information
Michael137 committed Sep 13, 2024
1 parent 637aa61 commit 4ca8fb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def _run_test(self, defines):
self.expect_var_path("shortstring", summary='"short"')
self.expect_var_path("longstring", summary='"I am a very long string"')

self.expect_expr("shortstring", result_summary='"short"')
self.expect_expr("longstring", result_summary='"I am a very long string"')


for v in [None, "ALTERNATE_LAYOUT"]:
for r in range(5):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {

struct __short {
value_type __data_[__min_cap];
#ifdef BITMASKS
#ifdef SUBCLASS_PADDING
struct : __padding<value_type> {
unsigned char __size_;
};
#else
#else // !SUBCLASS_PADDING

unsigned char __padding[sizeof(value_type) - 1];
#ifdef BITMASKS
unsigned char __size_;
#endif
#else // !BITMASKS
unsigned char __size_ : 7;
unsigned char __is_long_ : 1;
#endif
#endif // BITMASKS
#endif // SUBCLASS_PADDING
};

#ifdef BITMASKS
Expand Down

0 comments on commit 4ca8fb1

Please sign in to comment.