diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-08-10 10:56:17 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-08-10 10:56:17 +0000 |
commit | b448d1bf212219febbb182d00c210bad1bd25e7f (patch) | |
tree | 915ba501e5ddff31cf092a2a5700da1356545530 /lldb/packages/Python/lldbsuite/test | |
parent | c4b5b66a05bbf53573e4b2f1355b455bc7a37c64 (diff) | |
download | bcm5719-llvm-b448d1bf212219febbb182d00c210bad1bd25e7f.tar.gz bcm5719-llvm-b448d1bf212219febbb182d00c210bad1bd25e7f.zip |
[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
llvm-svn: 368511
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
5 files changed, 65 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp new file mode 100644 index 00000000000..4fde4ec3e14 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp @@ -0,0 +1,5 @@ +#include "ExtBase.h" + +char ExtBase::bar() { + return 'x'; +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h new file mode 100644 index 00000000000..28e139d3284 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h @@ -0,0 +1,3 @@ +class ExtBase { + virtual char bar(); +}; diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile new file mode 100644 index 00000000000..e1afdbd9ac9 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../../make +CXX_SOURCES := main.cpp ExtBase.cpp +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py new file mode 100644 index 00000000000..4c9058c1538 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py @@ -0,0 +1,3 @@ +from lldbsuite.test import lldbinline + +lldbinline.MakeInlineTest(__file__, globals(), []) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp new file mode 100644 index 00000000000..dd2a07b9927 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp @@ -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"]) +} |