[Lldb-commits] [lldb] r368511 - [lldb] Fix dynamic_cast by no longer failing on variable without metadata

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Sat Aug 10 03:56:17 PDT 2019


Author: teemperor
Date: Sat Aug 10 03:56:17 2019
New Revision: 368511

URL: http://llvm.org/viewvc/llvm-project?rev=368511&view=rev
Log:
[lldb] Fix dynamic_cast by no longer failing on variable without metadata

Summary:
Our IR rewriting infrastructure currently fails when it encounters a variable which has no metadata associated.
This causes dynamic_cast to fail as in this case IRForTarget considers the type info pointers ('@_ZTI...') to be
variables without associated metadata. As there are no variables for these internal variables, this is actually
not an error and dynamic_cast would work fine if we didn't throw this error.

This patch fixes this by removing this diagnostics code. In case we would actually hit a variable that has no
metadata (but is supposed to have), we still have the error in the expression log so this shouldn't make it
harder to diagnose any missing metadata errors.

This patch should fix dynamic_cast and also adds a bunch of test coverage to that language feature.

Fixes rdar://10813639

Reviewers: davide, labath

Reviewed By: labath

Subscribers: friss, labath, abidh, lldb-commits

Tags: #lldb

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

Added:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp
Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp?rev=368511&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp Sat Aug 10 03:56:17 2019
@@ -0,0 +1,5 @@
+#include "ExtBase.h"
+
+char ExtBase::bar() {
+  return 'x';
+}

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h?rev=368511&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h Sat Aug 10 03:56:17 2019
@@ -0,0 +1,3 @@
+class ExtBase {
+  virtual char bar();
+};

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile?rev=368511&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile Sat Aug 10 03:56:17 2019
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+CXX_SOURCES := main.cpp ExtBase.cpp
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py?rev=368511&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py Sat Aug 10 03:56:17 2019
@@ -0,0 +1,3 @@
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals(), [])

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp?rev=368511&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp Sat Aug 10 03:56:17 2019
@@ -0,0 +1,51 @@
+#include "ExtBase.h"
+
+class Base {
+public:
+  virtual char foo() {
+    return 'b';
+  }
+};
+
+class Derived : public Base {
+public:
+  char foo() override {
+    return 'd';
+  }
+};
+
+class NonOverrideDerived : public Base {
+};
+
+class ExtDerived : public ExtBase {
+public:
+  char bar() override {
+    return 'y';
+  }
+};
+
+int main() {
+  Derived d;
+  NonOverrideDerived d2;
+  Base *b = &d;
+  Base *real_base = new Base();
+  char c = dynamic_cast<Derived *>(b)->foo();
+
+  ExtDerived ext_d;
+  ExtBase *ext_b = &ext_d;
+  ExtBase *ext_real_base = new ExtBase();
+  c = dynamic_cast<ExtDerived *>(ext_b)->bar();
+
+
+  return 0; //% self.expect("expression dynamic_cast<class Derived *>(b) == (Derived*)b", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class Base *>(b) == (Base*)b", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class Derived *>(real_base) == nullptr", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class NonOverrideDerived *>(&d) == nullptr", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class ExtDerived *>(real_base) == nullptr", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class Derived *>(&d2) == nullptr", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class NonOverrideDerived *>(&d2) == (NonOverrideDerived *)&d2", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class Derived *>(&ext_d) == nullptr", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class ExtDerived *>(ext_b) == (class ExtDerived*)ext_b", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class ExtBase *>(ext_real_base) == (class ExtBase*)ext_real_base", substrs = ["bool", " = true"])
+            //% self.expect("expression dynamic_cast<class ExtDerived *>(ext_real_base) == nullptr", substrs = ["bool", " = true"])
+}

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp?rev=368511&r1=368510&r2=368511&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp Sat Aug 10 03:56:17 2019
@@ -1265,16 +1265,10 @@ bool IRForTarget::MaybeHandleVariable(Va
     clang::NamedDecl *named_decl = DeclForGlobal(global_variable);
 
     if (!named_decl) {
-      if (IsObjCSelectorRef(llvm_value_ptr))
-        return true;
-
-      if (!global_variable->hasExternalLinkage())
-        return true;
-
       LLDB_LOG(log, "Found global variable \"{0}\" without metadata",
                global_variable->getName());
 
-      return false;
+      return true;
     }
 
     llvm::StringRef name(named_decl->getName());




More information about the lldb-commits mailing list