[lldb] Add a test for class loading via member typedefs
authorRaphael Isemann <teemperor@gmail.com>
Mon, 1 Nov 2021 14:55:16 +0000 (15:55 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Mon, 1 Nov 2021 14:58:45 +0000 (15:58 +0100)
This is currently only tested indirectly in the huge stdlibc++ formatter tests.

lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile [new file with mode: 0644]
lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py [new file with mode: 0644]
lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp [new file with mode: 0644]

diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile
new file mode 100644 (file)
index 0000000..99998b2
--- /dev/null
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py
new file mode 100644 (file)
index 0000000..6d1a85f
--- /dev/null
@@ -0,0 +1,41 @@
+"""
+Tests loading of classes when the loading is triggered via a typedef inside the
+class (and not via the normal LLDB lookup that first resolves the surrounding
+class).
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test(self):
+        self.build()
+        self.createTestTarget()
+
+        # Print the top-level typedef which triggers the loading of the class
+        # that the typedef is defined inside.
+        self.expect_expr(
+            "pull_in_classes",
+            result_type="StructWithMember::MemberTypedef",
+            result_value="0",
+        )
+
+        # Print the classes and check their types.
+        self.expect_expr(
+            "struct_to_print",
+            result_type="StructWithMember",
+            result_children=[
+                ValueCheck(
+                    name="m",
+                    type="StructWithNested::Nested<int>::OtherTypedef",
+                    children=[ValueCheck(name="i", value="0", type="int")],
+                )
+            ],
+        )
diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp
new file mode 100644 (file)
index 0000000..ba08d3b
--- /dev/null
@@ -0,0 +1,31 @@
+struct TopLevelStruct {
+  int i;
+};
+
+// Contains a templated nested class with a typedef.
+struct StructWithNested {
+  template <typename T>
+  struct Nested {
+    // Typedef in a class. Intended to be referenced directly so that it can
+    // trigger the loading of the surrounding classes.
+    typedef TopLevelStruct OtherTypedef;
+  };
+};
+
+// Contains a typedef.
+struct StructWithMember {
+  // This member pulls in the typedef (and classes) above.
+  StructWithNested::Nested<int>::OtherTypedef m;
+  // Typedef in a class. Intended to be referenced directly so that it can
+  // trigger the loading of the surrounding class.
+  typedef int MemberTypedef;
+};
+
+// This is printed and will pull in the typedef in StructWithmember.
+StructWithMember::MemberTypedef pull_in_classes;
+
+
+StructWithMember struct_to_print;
+
+
+int main() {}