[Lldb-commits] [PATCH] D111931: [lldb] Filter duplicates in Target::GetScratchTypeSystems

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 19 02:50:18 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfaa5c344d5b: [lldb] Filter duplicates in Target::GetScratchTypeSystems (authored by teemperor).
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111931/new/

https://reviews.llvm.org/D111931

Files:
  lldb/source/Target/Target.cpp
  lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py


Index: lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py
@@ -0,0 +1,20 @@
+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_FindTypes_on_scratch_AST(self):
+        """
+        Tests FindTypes invoked with only LLDB's scratch AST present.
+        """
+        target = self.dbg.GetDummyTarget()
+        # There should be only one instance of 'unsigned long' in our single
+        # scratch AST. Note: FindTypes/SBType hahave no filter by language, so
+        # pick something that is unlikely to also be found in the scratch
+        # TypeSystem of other language plugins.
+        self.assertEqual(len(target.FindTypes("unsigned long")), 1)
Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -60,6 +60,7 @@
 #include "lldb/Utility/Timer.h"
 
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SetVector.h"
 
 #include <memory>
 #include <mutex>
@@ -2231,7 +2232,10 @@
   if (!m_valid)
     return {};
 
-  std::vector<TypeSystem *> scratch_type_systems;
+  // Some TypeSystem instances are associated with several LanguageTypes so
+  // they will show up several times in the loop below. The SetVector filters
+  // out all duplicates as they serve no use for the caller.
+  llvm::SetVector<TypeSystem *> scratch_type_systems;
 
   LanguageSet languages_for_expressions =
       Language::GetLanguagesSupportingTypeSystemsForExpressions();
@@ -2247,10 +2251,10 @@
                      "system available",
                      Language::GetNameForLanguageType(language));
     else
-      scratch_type_systems.emplace_back(&type_system_or_err.get());
+      scratch_type_systems.insert(&type_system_or_err.get());
   }
 
-  return scratch_type_systems;
+  return scratch_type_systems.takeVector();
 }
 
 PersistentExpressionState *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111931.380623.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211019/f6a5fe63/attachment-0001.bin>


More information about the lldb-commits mailing list