From 7e3ef4df2dc93795246a402c654a07e26e4bdbbe Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 20 Mar 2018 19:46:32 +0000 Subject: [ExpressionParser] Re-implement r327356 in a less disruptive way. Instead of applying the sledgehammer of refusing to insert any C++ symbol in the ASTContext, try to validate the decl if what we have is an operator. There was other code in lldb which was responsible for this, just not really exposed (or used) in this codepath. Also, add a better/more comprehensive test. llvm-svn: 328025 --- .../test/lang/cpp/operator-overload/Makefile | 20 ++++++++++++++++++++ .../cpp/operator-overload/TestOperatorOverload.py | 22 ++++++++++++++++++++++ .../test/lang/cpp/operator-overload/a.cpp | 9 +++++++++ .../test/lang/cpp/operator-overload/b.cpp | 10 ++++++++++ 4 files changed, 61 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp (limited to 'lldb/packages/Python/lldbsuite') diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile new file mode 100644 index 00000000000..7d85a3a81f8 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/Makefile @@ -0,0 +1,20 @@ +LEVEL = ../../../make + +CXX_SOURCES = a.cpp b.cpp +CXXFLAGS_NO_DEBUGINFO = -c +CXXFLAGS_DEBUGINFO = -c -g + +all: main + +main: a.o b.o + $(CXX) a.o b.o -o main $(LDFLAGS) + +a.o: a.cpp + $(CXX) $(SRCDIR)/a.cpp $(CXXFLAGS_NO_DEBUGINFO) -o a.o + +b.o: b.cpp + $(CXX) $(SRCDIR)/b.cpp $(CXXFLAGS_DEBUGINFO) -o b.o + +clean: OBJECTS += a.o b.o main + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py new file mode 100644 index 00000000000..0191e08d29f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/TestOperatorOverload.py @@ -0,0 +1,22 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestOperatorOverload(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def test_overload(self): + self.build() + (target, process, thread, + main_breakpoint) = lldbutil.run_to_source_breakpoint(self, + "break here", lldb.SBFileSpec("b.cpp"), exe_name = "main") + frame = thread.GetSelectedFrame() + value = frame.EvaluateExpression("x == nil") + self.assertTrue(str(value.GetError()) + .find("comparison between NULL and non-pointer ('Tinky' and NULL)") + != -1) + self.assertTrue(str(value.GetError()) + .find("invalid operands to binary expression ('Tinky' and 'long')") + != -1) + self.assertFalse(value.GetError().Success()) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp new file mode 100644 index 00000000000..77b2f6ace82 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/a.cpp @@ -0,0 +1,9 @@ +class Patatino { +public: + double _blah; + Patatino(int blah) : _blah(blah) {} +}; + +bool operator==(const Patatino& a, const Patatino& b) { + return a._blah < b._blah; +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp new file mode 100644 index 00000000000..c0eb29bb79f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/operator-overload/b.cpp @@ -0,0 +1,10 @@ +class Tinky { +public: + int _meh; + Tinky(int meh) : _meh(meh) {} +}; + +int main(void) { + Tinky x(12); + return 0; // break here +} -- cgit v1.2.3