Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / cpp / bitfields / TestCppBitfields.py
blobf796c635895ac1bdae6a399855dcea42e2fbfa07
1 """Show bitfields and check that they display correctly."""
3 import lldb
4 from lldbsuite.test.decorators import *
5 from lldbsuite.test.lldbtest import *
6 from lldbsuite.test import lldbutil
9 class CppBitfieldsTestCase(TestBase):
10 @no_debug_info_test
11 def test_bitfields(self):
12 self.build()
13 lldbutil.run_to_source_breakpoint(
14 self, "// break here", lldb.SBFileSpec("main.cpp", False)
17 # Accessing LargeBitsA.
18 self.expect_expr(
19 "lba",
20 result_children=[
21 ValueCheck(name="", type="int:32"),
22 ValueCheck(name="a", type="unsigned int:20", value="2"),
25 self.expect_expr("lba.a", result_type="unsigned int", result_value="2")
27 # Accessing LargeBitsB.
28 self.expect_expr(
29 "lbb",
30 result_children=[
31 ValueCheck(name="a", type="unsigned int:1", value="1"),
32 ValueCheck(name="", type="int:31"),
33 ValueCheck(name="b", type="unsigned int:20", value="3"),
36 self.expect_expr("lbb.b", result_type="unsigned int", result_value="3")
38 # Accessing LargeBitsC.
39 self.expect_expr(
40 "lbc",
41 result_children=[
42 ValueCheck(name="", type="int:22"),
43 ValueCheck(name="a", type="unsigned int:1", value="1"),
44 ValueCheck(name="b", type="unsigned int:1", value="0"),
45 ValueCheck(name="c", type="unsigned int:5", value="4"),
46 ValueCheck(name="d", type="unsigned int:1", value="1"),
47 ValueCheck(name="", type="int:2"),
48 ValueCheck(name="e", type="unsigned int:20", value="20"),
51 self.expect_expr("lbc.c", result_type="unsigned int", result_value="4")
53 # Accessing LargeBitsD.
54 self.expect_expr(
55 "lbd",
56 result_children=[
57 ValueCheck(name="arr", type="char[3]", summary='"ab"'),
58 ValueCheck(name="", type="int:32"),
59 ValueCheck(name="a", type="unsigned int:20", value="5"),
62 self.expect_expr("lbd.a", result_type="unsigned int", result_value="5")
64 # Test BitfieldsInStructInUnion.
65 # FIXME: This needs some more explanation for what it's actually testing.
66 nested_struct_children = [
67 ValueCheck(name="", type="int:22"),
68 ValueCheck(name="a", type="uint64_t:1", value="1"),
69 ValueCheck(name="b", type="uint64_t:1", value="0"),
70 ValueCheck(name="c", type="uint64_t:1", value="1"),
71 ValueCheck(name="d", type="uint64_t:1", value="0"),
72 ValueCheck(name="e", type="uint64_t:1", value="1"),
73 ValueCheck(name="f", type="uint64_t:1", value="0"),
74 ValueCheck(name="g", type="uint64_t:1", value="1"),
75 ValueCheck(name="h", type="uint64_t:1", value="0"),
76 ValueCheck(name="i", type="uint64_t:1", value="1"),
77 ValueCheck(name="j", type="uint64_t:1", value="0"),
78 ValueCheck(name="k", type="uint64_t:1", value="1"),
80 self.expect_expr(
81 "bitfields_in_struct_in_union",
82 result_type="BitfieldsInStructInUnion",
83 result_children=[
84 ValueCheck(
85 name="",
86 children=[ValueCheck(name="f", children=nested_struct_children)],
90 self.expect_expr(
91 "bitfields_in_struct_in_union.f.a", result_type="uint64_t", result_value="1"
94 # Unions with bitfields.
95 self.expect_expr(
96 "uwbf",
97 result_type="UnionWithBitfields",
98 result_children=[
99 ValueCheck(name="a", value="255"),
100 ValueCheck(name="b", value="65535"),
101 ValueCheck(name="c", value="4294967295"),
102 ValueCheck(name="x", value="4294967295"),
105 self.expect_expr(
106 "uwubf",
107 result_type="UnionWithUnnamedBitfield",
108 result_children=[
109 ValueCheck(name="a", value="16777215"),
110 ValueCheck(name="x", value="4294967295"),
114 # Class with a base class and a bitfield.
115 self.expect_expr(
116 "derived",
117 result_type="Derived",
118 result_children=[
119 ValueCheck(
120 name="Base",
121 children=[ValueCheck(name="b_a", value="2", type="uint32_t")],
123 ValueCheck(name="d_a", value="1", type="uint32_t:1"),
127 # Struct with bool bitfields.
128 self.expect_expr(
129 "bb",
130 result_type="",
131 result_children=[
132 ValueCheck(name="a", value="true", type="bool:1"),
133 ValueCheck(name="b", value="false", type="bool:1"),
134 ValueCheck(name="c", value="true", type="bool:2"),
135 ValueCheck(name="d", value="true", type="bool:2"),
139 bb = self.frame().FindVariable("bb")
140 self.assertSuccess(bb.GetError())
142 bb_a = bb.GetChildAtIndex(0)
143 self.assertSuccess(bb_a.GetError())
144 self.assertEqual(bb_a.GetValueAsUnsigned(), 1)
145 self.assertEqual(bb_a.GetValueAsSigned(), 1)
147 bb_b = bb.GetChildAtIndex(1)
148 self.assertSuccess(bb_b.GetError())
149 self.assertEqual(bb_b.GetValueAsUnsigned(), 0)
150 self.assertEqual(bb_b.GetValueAsSigned(), 0)
152 bb_c = bb.GetChildAtIndex(2)
153 self.assertSuccess(bb_c.GetError())
154 self.assertEqual(bb_c.GetValueAsUnsigned(), 1)
155 self.assertEqual(bb_c.GetValueAsSigned(), 1)
157 bb_d = bb.GetChildAtIndex(3)
158 self.assertSuccess(bb_d.GetError())
159 self.assertEqual(bb_d.GetValueAsUnsigned(), 1)
160 self.assertEqual(bb_d.GetValueAsSigned(), 1)
162 # Test a class with a base class that has a vtable ptr. The derived
163 # class has bitfields.
164 base_with_vtable_children = [
165 ValueCheck(name="a", type="unsigned int:4", value="5"),
166 ValueCheck(name="b", type="unsigned int:4", value="0"),
167 ValueCheck(name="c", type="unsigned int:4", value="5"),
169 self.expect_expr("base_with_vtable", result_children=base_with_vtable_children)
170 self.expect_var_path("base_with_vtable", children=base_with_vtable_children)
172 @no_debug_info_test
173 def test_bitfield_behind_vtable_ptr(self):
174 self.build()
175 lldbutil.run_to_source_breakpoint(
176 self, "// break here", lldb.SBFileSpec("main.cpp", False)
179 # Test a class with a vtable ptr and bitfields.
180 with_vtable_children = [
181 ValueCheck(name="a", type="unsigned int:4", value="5"),
182 ValueCheck(name="b", type="unsigned int:4", value="0"),
183 ValueCheck(name="c", type="unsigned int:4", value="5"),
185 self.expect_expr("with_vtable", result_children=with_vtable_children)
186 self.expect_var_path("with_vtable", children=with_vtable_children)
188 # Test a class with a vtable ptr and unnamed bitfield directly after.
189 with_vtable_and_unnamed_children = [
190 ValueCheck(name="", type="int:4", value="0"),
191 ValueCheck(name="b", type="unsigned int:4", value="0"),
192 ValueCheck(name="c", type="unsigned int:4", value="5"),
194 self.expect_expr(
195 "with_vtable_and_unnamed", result_children=with_vtable_and_unnamed_children
197 self.expect_var_path(
198 "with_vtable_and_unnamed", children=with_vtable_and_unnamed_children
201 derived_with_vtable_children = [
202 ValueCheck(
203 name="Base",
204 children=[ValueCheck(name="b_a", value="2", type="uint32_t")],
206 ValueCheck(name="a", value="1", type="unsigned int:1"),
208 self.expect_expr(
209 "derived_with_vtable", result_children=derived_with_vtable_children
211 self.expect_var_path(
212 "derived_with_vtable", children=derived_with_vtable_children