Skip to content

Commit ca0c533

Browse files
committed
fixup! make test bi-directional
1 parent 918efaa commit ca0c533

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

lldb/test/API/lang/cpp/typedef-to-outer-fwd/TestTypedefToOuterFwd.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@
66

77
class TestCaseTypedefToOuterFwd(TestBase):
88
"""
9-
We are stopped in main.o, which only sees a forward declaration
10-
of FooImpl. We then try to get the FooImpl::Ref typedef (whose
11-
definition is in lib.o). Make sure we correctly resolve this
12-
typedef.
13-
"""
9+
We a global variable whose type is forward declared. We then
10+
try to get the Ref typedef (whose definition is in either main.o
11+
or lib.o). Make sure we correctly resolve this typedef.
1412
15-
def test(self):
16-
self.build()
17-
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
18-
self, "return", lldb.SBFileSpec("main.cpp")
19-
)
13+
We test this for two cases, where the definition lives
14+
in main.o or lib.o.
15+
"""
2016

21-
foo = thread.frames[0].FindVariable("foo")
22-
self.assertSuccess(foo.GetError(), "Found foo")
17+
def check_global_var(self, target, name: str):
18+
var = target.FindFirstGlobalVariable(name)
19+
self.assertSuccess(var.GetError(), f"Found {name}")
2320

24-
foo_type = foo.GetType()
25-
self.assertTrue(foo_type)
21+
var_type = var.GetType()
22+
self.assertTrue(var_type)
2623

27-
impl = foo_type.GetPointeeType()
24+
impl = var_type.GetPointeeType()
2825
self.assertTrue(impl)
2926

3027
ref = impl.FindDirectNestedType("Ref")
3128
self.assertTrue(ref)
3229

33-
self.assertEqual(ref.GetCanonicalType(), foo_type)
30+
self.assertEqual(ref.GetCanonicalType(), var_type)
31+
32+
def test_definition_in_main(self):
33+
self.build()
34+
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
35+
self.check_global_var(target, "gLibExternalDef")
36+
37+
def test_definition_in_lib(self):
38+
self.build()
39+
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
40+
self.check_global_var(target, "gMainExternalDef")

lldb/test/API/lang/cpp/typedef-to-outer-fwd/lib.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@ template <typename T> struct FooImpl {
66
Ref Create() { return new FooImpl<T>(); }
77
};
88

9-
Foo getString() {
10-
FooImpl<char> impl;
11-
Foo ret;
12-
ret.impl = impl.Create();
13-
14-
return ret;
15-
}
9+
FooImpl<char> gLibLocalDef;
10+
BarImpl<char> *gLibExternalDef = nullptr;

lldb/test/API/lang/cpp/typedef-to-outer-fwd/lib.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#define LIB_H_IN
33

44
template <typename T> struct FooImpl;
5-
6-
struct Foo {
7-
FooImpl<char> *impl = nullptr;
8-
};
5+
template <typename T> struct BarImpl;
96

107
#endif // LIB_H_IN
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "lib.h"
22

3-
extern Foo getString();
3+
template <typename T> struct BarImpl {
4+
using Ref = BarImpl<T> *;
45

5-
int main() {
6-
FooImpl<char> *foo = getString().impl;
7-
return 0;
8-
}
6+
Ref Create() { return new BarImpl<T>(); }
7+
};
8+
9+
BarImpl<char> gMainLocalDef;
10+
FooImpl<char> *gMainExternalDef = nullptr;
11+
12+
int main() { return 0; }

0 commit comments

Comments
 (0)