[Lldb-commits] [lldb] 950f1bf - [lldb] Add SubstTemplateTypeParm to RemoveWrappingTypes

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 11 05:32:08 PDT 2020


Author: Raphael Isemann
Date: 2020-08-11T14:31:47+02:00
New Revision: 950f1bf976b332eca60267b25bf759e2ad564e0c

URL: https://github.com/llvm/llvm-project/commit/950f1bf976b332eca60267b25bf759e2ad564e0c
DIFF: https://github.com/llvm/llvm-project/commit/950f1bf976b332eca60267b25bf759e2ad564e0c.diff

LOG: [lldb] Add SubstTemplateTypeParm to RemoveWrappingTypes

Like the other type sugar removed by RemoveWrappingTypes, SubstTemplateTypeParm
is just pure sugar that should be ignored. If we don't ignore it (as we do now),
LLDB will fail to read values from record fields that have a
SubstTemplateTypeParm type.

Only way to produce such a type in LLDB is to either use the `import-std-module`
setting to get a template into the expression parser or just create your own
template directly in the expression parser which is what we do in the test.

Reviewed By: jarin

Differential Revision: https://reviews.llvm.org/D85132

Added: 
    lldb/test/API/lang/cpp/subst_template_type_param/TestSubstTemplateTypeParam.py

Modified: 
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index a1bde107bf7a..7f5fdb5b0d91 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2499,6 +2499,7 @@ RemoveWrappingTypes(QualType type, ArrayRef<clang::Type::TypeClass> mask = {}) {
     case clang::Type::Decltype:
     case clang::Type::Elaborated:
     case clang::Type::Paren:
+    case clang::Type::SubstTemplateTypeParm:
     case clang::Type::TemplateSpecialization:
     case clang::Type::Typedef:
     case clang::Type::TypeOf:

diff  --git a/lldb/test/API/lang/cpp/subst_template_type_param/TestSubstTemplateTypeParam.py b/lldb/test/API/lang/cpp/subst_template_type_param/TestSubstTemplateTypeParam.py
new file mode 100644
index 000000000000..528ed94db089
--- /dev/null
+++ b/lldb/test/API/lang/cpp/subst_template_type_param/TestSubstTemplateTypeParam.py
@@ -0,0 +1,34 @@
+"""
+Test SubstTemplateTypeParam types which are produced as type sugar
+when template type parameters are used for example as field types.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import decorators
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_typedef(self):
+        target = self.dbg.GetDummyTarget()
+
+        # Declare a template class with a field that uses the template type
+        # parameter.
+        opts = lldb.SBExpressionOptions()
+        opts.SetTopLevel(True)
+        result = target.EvaluateExpression("template <typename T> struct X { T f; };", opts)
+        # FIXME: This fails with "Couldn't find $__lldb_expr() in the module"
+        # but it should succeed. The fact that this code has nothing to run
+        # shouldn't be an error.
+        # self.assertSuccess(result.GetError())
+
+        # Instantiate and produce a value with that template as the type.
+        # The field in the value will have a SubstTemplateTypeParam that
+        # should behave like a normal field.
+        result = target.EvaluateExpression("X<int> x; x.f = 123; x")
+        self.assertEqual(result.GetNumChildren(), 1)
+        self.assertEqual(result.GetChildAtIndex(0).GetTypeName(), "int")
+        self.assertEqual(result.GetChildAtIndex(0).GetValue(), "123")


        


More information about the lldb-commits mailing list