[Lldb-commits] [PATCH] D59217: Fix/unify SBType comparison

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 11 09:34:42 PDT 2019

labath created this revision.
labath added reviewers: clayborg, aprantl.
Herald added a reviewer: serge-sans-paille.
Herald added a subscriber: jdoerfert.

In my next step at cleaning up modify-python-lldb.py, I started focusing
on equality comparison. To my surprise, I found out that both python and
c++ versions of the SBType class implement equality comparison, but each
one does it differently. While the python version was implemented in
terms of type name equality, the C++ one used a deep comparison on the
underlying objects.

Removing the python version caused one test to fail (TestTypeList). This
happened because the c++ version of operator== boiled down to
TypePair::operator==, which contains two items: the compiler_type and
type_sp. In this case, the compiler_type was identical, but one of the
objects had the type_sp field unset.

I tried fixing the code so that both objects keep their type_sp member,
but it wasn't easy, because there are so many operations which just work
with the CompilerType types, and so any operation on the SBType (the
test in question was doing GetPointeeType on the type of one variable
and expecting it to match the type of another variable), cause that
second member to be lost.

So instead, I tried to relax the equality comparison on the TypePair
class. Now, this class ignores the type_sp for the purposes of
comparison, and uses the CompilerType only. This seems reasonable, as
each TypeSP is able to convert itself to a CompilerType, though I don't
understand the full implications of this (e.g., is there any case where
two different TypeSPs might end up returning different CompilerTypes).



Index: scripts/interface/SBType.i
--- scripts/interface/SBType.i
+++ scripts/interface/SBType.i
@@ -322,6 +322,10 @@
     GetTypeFlags ();
+    bool operator==(lldb::SBType &rhs);
+    bool operator!=(lldb::SBType &rhs);
     %pythoncode %{
         def template_arg_array(self):
             num_args = self.num_template_args
Index: scripts/Python/modify-python-lldb.py
--- scripts/Python/modify-python-lldb.py
+++ scripts/Python/modify-python-lldb.py
@@ -143,7 +143,6 @@
      'SBWatchpoint': ['GetID'],
      'SBFileSpec': ['GetFilename', 'GetDirectory'],
      'SBModule': ['GetFileSpec', 'GetUUIDString'],
-     'SBType': ['GetByteSize', 'GetName']
Index: include/lldb/Symbol/Type.h
--- include/lldb/Symbol/Type.h
+++ include/lldb/Symbol/Type.h
@@ -256,14 +256,10 @@
   explicit operator bool() const { return IsValid(); }
   bool operator==(const TypePair &rhs) const {
-    return compiler_type == rhs.compiler_type &&
-           type_sp.get() == rhs.type_sp.get();
+    return compiler_type == rhs.compiler_type;
-  bool operator!=(const TypePair &rhs) const {
-    return compiler_type != rhs.compiler_type ||
-           type_sp.get() != rhs.type_sp.get();
-  }
+  bool operator!=(const TypePair &rhs) const { return !(*this == rhs); }
   void Clear() {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59217.190106.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190311/58b95940/attachment.bin>

More information about the lldb-commits mailing list