Skip to content

Commit da5c7a0

Browse files
committed
[lldb][test] TestDataFormatterLibcxxStringSimulator.py: fix padding for 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. (cherry picked from commit 4ca8fb1)
1 parent 8def859 commit da5c7a0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def _run_test(self, defines):
2222
self.expect_var_path("shortstring", summary='"short"')
2323
self.expect_var_path("longstring", summary='"I am a very long string"')
2424

25+
self.expect_expr("shortstring", result_summary='"short"')
26+
self.expect_expr("longstring", result_summary='"I am a very long string"')
27+
2528

2629
for v in [None, "ALTERNATE_LAYOUT"]:
2730
for r in range(5):

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
7171

7272
struct __short {
7373
value_type __data_[__min_cap];
74-
#ifdef BITMASKS
7574
#ifdef SUBCLASS_PADDING
7675
struct : __padding<value_type> {
7776
unsigned char __size_;
7877
};
79-
#else
78+
#else // !SUBCLASS_PADDING
79+
8080
unsigned char __padding[sizeof(value_type) - 1];
81+
#ifdef BITMASKS
8182
unsigned char __size_;
82-
#endif
8383
#else // !BITMASKS
8484
unsigned char __size_ : 7;
8585
unsigned char __is_long_ : 1;
86-
#endif
86+
#endif // BITMASKS
87+
#endif // SUBCLASS_PADDING
8788
};
8889

8990
#ifdef BITMASKS

0 commit comments

Comments
 (0)