[Lldb-commits] [lldb] [lldb][test] TestDataFormatterLibcxxStringSimulator.py: add new padding layout (PR #108169)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 11 04:57:04 PDT 2024
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/108169
>From fd093d23400fc48b013cafceafc009fcb5f2142c Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Sep 2024 09:32:13 +0100
Subject: [PATCH 1/2] [lldb][test] TestDataFormatterLibcxxStringSimulator.py:
add new padding layout
---
.../TestDataFormatterLibcxxStringSimulator.py | 4 ++-
.../libcxx-simulators/string/main.cpp | 33 +++++++++++++++----
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 3e5c493692c4f0..6adc7b12932e16 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
@@ -21,10 +21,12 @@ 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):
+ for r in range(6):
name = "test_r%d" % r
defines = ["REVISION=%d" % r]
if v:
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
index 7beeb9c39de49e..84d21b5dd5f2d6 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
@@ -20,7 +20,11 @@
// Pre-D128285 layout.
#define PACKED_ANON_STRUCT
#endif
-// REVISION == 4: current layout
+#if REVISION <= 4
+// Pre-TODO layout.
+#define UB_PADDING
+#endif
+// REVISION == 5: current layout
#ifdef PACKED_ANON_STRUCT
#define BEGIN_PACKED_ANON_STRUCT struct __attribute__((packed)) {
@@ -34,13 +38,23 @@
namespace std {
namespace __lldb {
-#if defined(ALTERNATE_LAYOUT) && defined(SUBCLASS_PADDING)
+#if defined(ALTERNATE_LAYOUT)
+#if 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 // !SUBCLASS_PADDING
+template <size_t _PaddingSize>
+struct __padding {
+ char __padding_[_PaddingSize];
+};
+
+template <>
+struct __padding<0> {};
+#endif // SUBCLASS_PADDING
+#endif // ALTERNATE_LAYOUT
template <class _CharT, class _Traits, class _Allocator> class basic_string {
public:
@@ -71,18 +85,23 @@ 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
+#elif defined(UB_PADDING)
unsigned char __padding[sizeof(value_type) - 1];
- unsigned char __size_;
+#else
+ [[no_unique_address]] __padding<sizeof(value_type) - 1> __padding_;
#endif
-#else // !BITMASKS
+
+#ifndef SUBCLASS_PADDING
+#ifdef BITMASKS
+ unsigned char __size_;
+#else
unsigned char __size_ : 7;
unsigned char __is_long_ : 1;
+#endif
#endif
};
>From 92e78bdf25404830cfd7bceaa2ec32fa894d15d7 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Sep 2024 12:56:46 +0100
Subject: [PATCH 2/2] fixup! clang-format
---
.../data-formatter-stl/libcxx-simulators/string/main.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
index 84d21b5dd5f2d6..74ec6f04ced3fa 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
@@ -45,14 +45,12 @@ template <class _CharT, size_t = sizeof(_CharT)> struct __padding {
};
template <class _CharT> struct __padding<_CharT, 1> {};
-#else // !SUBCLASS_PADDING
-template <size_t _PaddingSize>
-struct __padding {
+#else // !SUBCLASS_PADDING
+template <size_t _PaddingSize> struct __padding {
char __padding_[_PaddingSize];
};
-template <>
-struct __padding<0> {};
+template <> struct __padding<0> {};
#endif // SUBCLASS_PADDING
#endif // ALTERNATE_LAYOUT
More information about the lldb-commits
mailing list