Author: Raphael Isemann
Date: 2021-11-01T15:58:45+01:00
New Revision: 9e0a39f3787ac055631891be9062dcd561cf4501

URL: 
https://github.com/llvm/llvm-project/commit/9e0a39f3787ac055631891be9062dcd561cf4501
DIFF: 
https://github.com/llvm/llvm-project/commit/9e0a39f3787ac055631891be9062dcd561cf4501.diff

LOG: [lldb] Add a test for class loading via member typedefs

This is currently only tested indirectly in the huge stdlibc++ formatter tests.

Added: 
    lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile
    
lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py
    lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp

Modified: 
    

Removed: 
    


################################################################################
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
index 0000000000000..99998b20bcb05
--- /dev/null
+++ b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile
@@ -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
index 0000000000000..6d1a85fff7214
--- /dev/null
+++ 
b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py
@@ -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
index 0000000000000..ba08d3bcbfd59
--- /dev/null
+++ b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp
@@ -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() {}


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to