Skip to content

[lldb][test] TestDataFormatterLibcxxStringSimulator.py: add new padding layout #108375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _run_test(self, defines):


for v in [None, "ALTERNATE_LAYOUT"]:
for r in range(5):
for r in range(6):
for c in range(3):
name = "test_r%d_c%d" % (r, c)
defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
// Pre-D128285 layout.
#define PACKED_ANON_STRUCT
#endif
// REVISION == 4: current layout
#if REVISION <= 4
// Pre-2a1ef74 layout.
#define NON_STANDARD_PADDING
#endif
// REVISION == 5: current layout

#ifdef PACKED_ANON_STRUCT
#define BEGIN_PACKED_ANON_STRUCT struct __attribute__((packed)) {
Expand All @@ -34,13 +38,21 @@
namespace std {
namespace __lldb {

#ifdef NON_STANDARD_PADDING
#if defined(ALTERNATE_LAYOUT) && defined(SUBCLASS_PADDING)
template <class _CharT, size_t = sizeof(_CharT)> struct __padding {
unsigned char __xx[sizeof(_CharT) - 1];
};

template <class _CharT> struct __padding<_CharT, 1> {};
#endif
#else // !NON_STANDARD_PADDING
template <size_t _PaddingSize> struct __padding {
char __padding_[_PaddingSize];
};

template <> struct __padding<0> {};
#endif

template <class _CharT, class _Traits, class _Allocator> class basic_string {
public:
Expand Down Expand Up @@ -77,7 +89,12 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
};
#else // !SUBCLASS_PADDING

#ifdef NON_STANDARD_PADDING
unsigned char __padding[sizeof(value_type) - 1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that (the zero sized array) really UB? Or just a compiler extension?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll rename it to NON_STANDARD_PADDING

#else
[[no_unique_address]] __padding<sizeof(value_type) - 1> __padding_;
#endif

#ifdef BITMASKS
unsigned char __size_;
#else // !BITMASKS
Expand Down Expand Up @@ -129,21 +146,26 @@ template <class _CharT, class _Traits, class _Allocator> class basic_string {
union {
#ifdef BITMASKS
unsigned char __size_;
#else
#else // !BITMASKS
struct {
unsigned char __is_long_ : 1;
unsigned char __size_ : 7;
};
#endif
#endif // BITMASKS
value_type __lx;
};
#else
#else // !SHORT_UNION
BEGIN_PACKED_ANON_STRUCT
unsigned char __is_long_ : 1;
unsigned char __size_ : 7;
END_PACKED_ANON_STRUCT
char __padding_[sizeof(value_type) - 1];
#endif
#ifdef NON_STANDARD_PADDING
unsigned char __padding[sizeof(value_type) - 1];
#else // !NON_STANDARD_PADDING
[[no_unique_address]] __padding<sizeof(value_type) - 1> __padding_;
#endif // NON_STANDARD_PADDING

#endif // SHORT_UNION
value_type __data_[__min_cap];
};

Expand Down
Loading