From 2ce889fa4e5cab75fc65d03a4dfae52784d57db9 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 30 Aug 2021 15:16:18 +0200 Subject: [PATCH] [lldb][NFC] Add size tests for empty records with alignment and with empty members This came up during the Windows bot failure discussing after D105471 . See also 3d9a9fa6911a5228ce799a7c639e94d322678934 . --- lldb/test/API/lang/c/sizeof/TestCSizeof.py | 1 + lldb/test/API/lang/c/sizeof/main.c | 7 ++++++- lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py | 4 ++++ lldb/test/API/lang/cpp/sizeof/main.cpp | 13 +++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/lang/c/sizeof/TestCSizeof.py b/lldb/test/API/lang/c/sizeof/TestCSizeof.py index 5bcbc42..6776683 100644 --- a/lldb/test/API/lang/c/sizeof/TestCSizeof.py +++ b/lldb/test/API/lang/c/sizeof/TestCSizeof.py @@ -14,5 +14,6 @@ class TestCase(TestBase): # Empty structs are not allowed in C, but Clang/GCC allow them and # give them a size of 0. self.expect_expr("sizeof(Empty) == sizeof_empty", result_value="true") + self.expect_expr("sizeof(EmptyMember) == sizeof_empty_member", result_value="true") self.expect_expr("sizeof(SingleMember) == sizeof_single", result_value="true") self.expect_expr("sizeof(PaddingMember) == sizeof_padding", result_value="true") diff --git a/lldb/test/API/lang/c/sizeof/main.c b/lldb/test/API/lang/c/sizeof/main.c index 08bf906..fa7bd2d 100644 --- a/lldb/test/API/lang/c/sizeof/main.c +++ b/lldb/test/API/lang/c/sizeof/main.c @@ -1,4 +1,7 @@ struct Empty {}; +struct EmptyMember { + char i[0]; +}; struct SingleMember { int i; }; @@ -9,13 +12,15 @@ struct PaddingMember { }; const unsigned sizeof_empty = sizeof(struct Empty); +const unsigned sizeof_empty_member = sizeof(struct EmptyMember); const unsigned sizeof_single = sizeof(struct SingleMember); const unsigned sizeof_padding = sizeof(struct PaddingMember); int main() { struct Empty empty; + struct EmptyMember empty_member; struct SingleMember single; struct PaddingMember padding; // Make sure globals are used. - return sizeof_empty + sizeof_single + sizeof_padding; + return sizeof_empty + sizeof_empty_member + sizeof_single + sizeof_padding; } diff --git a/lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py b/lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py index c6b54de..e7f4623 100644 --- a/lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py +++ b/lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py @@ -14,6 +14,10 @@ class TestCase(TestBase): # Empty structs/classes have size 1 in C++. self.expect_expr("sizeof(Empty) == sizeof_empty", result_value="true") self.expect_expr("sizeof(EmptyClass) == sizeof_empty_class", result_value="true") + self.expect_expr("sizeof(EmptyClassAligned) == sizeof_empty_class_aligned", + result_value="true") + self.expect_expr("sizeof(ClassEmptyMember) == sizeof_class_empty_member", + result_value="true") self.expect_expr("sizeof(SingleMember) == sizeof_single", result_value="true") self.expect_expr("sizeof(SingleMemberClass) == sizeof_single_class", result_value="true") self.expect_expr("sizeof(PaddingMember) == sizeof_padding", result_value="true") diff --git a/lldb/test/API/lang/cpp/sizeof/main.cpp b/lldb/test/API/lang/cpp/sizeof/main.cpp index 6c4da06..4a7a89a 100644 --- a/lldb/test/API/lang/cpp/sizeof/main.cpp +++ b/lldb/test/API/lang/cpp/sizeof/main.cpp @@ -1,5 +1,9 @@ struct Empty {}; class EmptyClass {}; +class alignas(4) EmptyClassAligned {}; +class ClassEmptyMember { + int i[0]; +}; struct SingleMember { int i; @@ -19,6 +23,8 @@ class PaddingMemberClass { const unsigned sizeof_empty = sizeof(Empty); const unsigned sizeof_empty_class = sizeof(EmptyClass); +const unsigned sizeof_empty_class_aligned = sizeof(EmptyClassAligned); +const unsigned sizeof_class_empty_member = sizeof(ClassEmptyMember); const unsigned sizeof_single = sizeof(SingleMember); const unsigned sizeof_single_class = sizeof(SingleMemberClass); const unsigned sizeof_padding = sizeof(PaddingMember); @@ -27,11 +33,14 @@ const unsigned sizeof_padding_class = sizeof(PaddingMemberClass); int main() { Empty empty; EmptyClass empty_class; + EmptyClassAligned empty_class_aligned; + ClassEmptyMember class_empty_member; SingleMember single; SingleMemberClass single_class; PaddingMember padding; PaddingMemberClass padding_class; // Make sure globals are used. - return sizeof_empty + sizeof_empty_class + sizeof_single + - sizeof_single_class + sizeof_padding + sizeof_padding_class; + return sizeof_empty + sizeof_empty_class + sizeof_class_empty_member + + sizeof_single + +sizeof_empty_class_aligned + sizeof_single_class + + sizeof_padding + sizeof_padding_class; } -- 2.7.4