Skip to content

Commit 9548dbe

Browse files
committed
[lldb][test] Add TestNoUniqueAddress.py
Tests that run expressions on record types with `[[no_unique_address]]` fields.
1 parent b54be00 commit 9548dbe

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Test that LLDB correctly handles fields
3+
marked with [[no_unique_address]].
4+
"""
5+
6+
import lldb
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import lldbutil
10+
11+
12+
class NoUniqueAddressTestCase(TestBase):
13+
def test(self):
14+
self.build()
15+
lldbutil.run_to_source_breakpoint(
16+
self, "return 0", lldb.SBFileSpec("main.cpp", False)
17+
)
18+
19+
# Qualified/unqualified lookup to templates in namespace
20+
self.expect_expr(
21+
"b1",
22+
result_type="basic::Foo",
23+
result_children=[ValueCheck(name="a", type="Empty")],
24+
)
25+
26+
self.expect_expr(
27+
"b2",
28+
result_type="bases::Foo",
29+
result_children=[
30+
ValueCheck(
31+
type="bases::B", children=[ValueCheck(name="x", type="Empty")]
32+
),
33+
ValueCheck(
34+
type="bases::A",
35+
children=[
36+
ValueCheck(name="c", type="long", value="1"),
37+
ValueCheck(name="d", type="long", value="2"),
38+
],
39+
),
40+
ValueCheck(
41+
type="bases::C", children=[ValueCheck(name="x", type="Empty")]
42+
),
43+
],
44+
)
45+
self.expect_expr(
46+
"b3",
47+
result_type="bases::Bar",
48+
result_children=[
49+
ValueCheck(
50+
type="bases::B", children=[ValueCheck(name="x", type="Empty")]
51+
),
52+
ValueCheck(
53+
type="bases::C", children=[ValueCheck(name="x", type="Empty")]
54+
),
55+
ValueCheck(
56+
type="bases::A",
57+
children=[
58+
ValueCheck(name="c", type="long", value="5"),
59+
ValueCheck(name="d", type="long", value="6"),
60+
],
61+
),
62+
],
63+
)
64+
65+
self.expect("frame var b1")
66+
self.expect("frame var b2")
67+
self.expect("frame var b3")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
struct Empty {};
2+
3+
namespace basic {
4+
struct Foo {
5+
[[no_unique_address]] Empty a;
6+
};
7+
} // namespace basic
8+
9+
namespace bases {
10+
struct A {
11+
long c, d;
12+
};
13+
14+
struct B {
15+
[[no_unique_address]] Empty x;
16+
};
17+
18+
struct C {
19+
[[no_unique_address]] Empty x;
20+
};
21+
22+
struct Foo : B, A, C {};
23+
struct Bar : B, C, A {};
24+
} // namespace bases
25+
26+
int main() {
27+
basic::Foo b1;
28+
bases::Foo b2;
29+
bases::Bar b3;
30+
b2.c = 1;
31+
b2.d = 2;
32+
b3.c = 5;
33+
b3.d = 6;
34+
return 0;
35+
}

0 commit comments

Comments
 (0)