[Lldb-commits] [RFC] Type lookup for template types is broken...

Frédéric Riss via lldb-commits lldb-commits at lists.llvm.org
Mon May 7 14:19:23 PDT 2018

(...At least when using accelerator tables)

If you apply the following patch, TestClassTemplateParameterPack.py will start failing:
diff --git a/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/main.cpp
index 90e63b40f..304872a15 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/main.cpp
+++ b/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/main.cpp
@@ -37,7 +37,7 @@ template <> struct D<int, int, bool> : D<int, int> {
 int main (int argc, char const *argv[])
-    C<int,16,32> myC;
+    C<int,16,32> myC; //% self.runCmd("settings set target.experimental.inject-local-vars false")
     C<int,16> myLesserC;
     myC.member = 64;

The test does things like invoke methods on temporary template objects:
//% self.expect("expression -- C<int, 16>().isSixteenThirtyTwo()", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["false"])

The above expression currently works because there’s a local of type C<int, 16>. With injected locals, the type is made readily available to Clang. No type lookup is required for this to work in this setup.

If you stop injecting locals, the test fails. We don’t provide the information to Clang to understand what C is. The reason is that when Clang parses “C<int , 16>”, it is going to ask about “C”, not the fully templated name. Our accelerator tables contain references to the full names, but not to C alone and we never find it. If I change Clang and dsymutil to add an accelerator for “C” each time an instance of C is seen then it nearly works. I just need this additional lldb patch:
diff --git a/source/Symbol/TypeMap.cpp b/source/Symbol/TypeMap.cpp
index 2838039ad..d2f2026bf 100644
--- a/source/Symbol/TypeMap.cpp
+++ b/source/Symbol/TypeMap.cpp
@@ -227,8 +227,11 @@ void TypeMap::RemoveMismatchedTypes(const std::string &type_scope,
       } else {
         // The type we are currently looking at doesn't exists in a namespace
         // or class, so it only matches if there is no type scope...
-        keep_match =
-            type_scope.empty() && type_basename.compare(match_type_name) == 0;
+        if (type_scope.empty()) {
+          keep_match = type_basename.compare(match_type_name) == 0 ||
+            (strlen(match_type_name) > type_basename.size() &&
+             match_type_name[type_basename.size()] == '<');
+        }

I didn’t post this as a Phabricator review as it requires changes in llvm before doing anything in LLDB and I wanted to make sure we agree this is the right thing to do. I’m also not sure if this works out of the box on platforms without accelerator tables.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180507/ccf52fd7/attachment-0001.html>

More information about the lldb-commits mailing list