diff options
author | Pavel Labath <labath@google.com> | 2016-08-15 14:32:32 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-08-15 14:32:32 +0000 |
commit | 1ac2b20d25869f7dafd8a5f9b99f43eb60a07bb2 (patch) | |
tree | c641f44aee757720089228a31b3c69d79a4ec32c /lldb/packages/Python/lldbsuite/test | |
parent | ad61c170d5ac9f5a6fa22ad7ddac7e58daa6b46e (diff) | |
download | bcm5719-llvm-1ac2b20d25869f7dafd8a5f9b99f43eb60a07bb2.tar.gz bcm5719-llvm-1ac2b20d25869f7dafd8a5f9b99f43eb60a07bb2.zip |
Fix expression evaluation with operator new
Summary:
referencing a user-defined operator new was triggering an assert in clang because we were
registering the function name as string "operator new", instead of using the special operator
enum, which clang has for this purpose. Method operators already had code to handle this, and now
I extend this to cover free standing operator functions as well. Test included.
Reviewers: spyffe
Subscribers: sivachandra, paulherman, lldb-commits
Differential Revision: http://reviews.llvm.org/D17856
llvm-svn: 278670
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py | 32 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/main.cpp | 26 |
2 files changed, 54 insertions, 4 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py index eac78cd2995..50f25485216 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py @@ -10,8 +10,7 @@ class TestCppGlobalOperators(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") - def test_with_run_command(self): + def prepare_executable_and_get_frame(self): self.build() # Get main source file @@ -42,8 +41,11 @@ class TestCppGlobalOperators(TestBase): self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) - # Check if global operators are evaluated - frame = thread.GetSelectedFrame() + return thread.GetSelectedFrame() + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + def test_equals_operator(self): + frame = self.prepare_executable_and_get_frame() test_result = frame.EvaluateExpression("operator==(s1, s2)") self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "operator==(s1, s2) = false") @@ -53,3 +55,25 @@ class TestCppGlobalOperators(TestBase): test_result = frame.EvaluateExpression("operator==(s2, s3)") self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "operator==(s2, s3) = false") + + def do_new_test(self, frame, expr, expected_value_name): + """Evaluate a new expression, and check its result""" + + expected_value = frame.FindValue(expected_value_name, lldb.eValueTypeVariableGlobal) + self.assertTrue(expected_value.IsValid()) + + expected_value_addr = expected_value.AddressOf() + self.assertTrue(expected_value_addr.IsValid()) + + got = frame.EvaluateExpression(expr) + self.assertTrue(got.IsValid()) + self.assertEqual(got.GetValueAsUnsigned(), expected_value_addr.GetValueAsUnsigned()) + got_type = got.GetType() + self.assertTrue(got_type.IsPointerType()) + self.assertEqual(got_type.GetPointeeType().GetName(), "Struct") + + def test_operator_new(self): + frame = self.prepare_executable_and_get_frame() + + self.do_new_test(frame, "new Struct()", "global_new_buf") + self.do_new_test(frame, "new(new_tag) Struct()", "tagged_new_buf") diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/main.cpp index a0dd0787fa3..c6dafd29586 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/global_operators/main.cpp @@ -1,3 +1,10 @@ +#include <new> + +struct new_tag_t +{ +}; +new_tag_t new_tag; + struct Struct { int value; }; @@ -6,6 +13,25 @@ bool operator==(const Struct &a, const Struct &b) { return a.value == b.value; } +typedef char buf_t[sizeof(Struct)]; +buf_t global_new_buf, tagged_new_buf; + +// This overrides global operator new +// This function and the following does not actually allocate memory. We are merely +// trying to make sure it is getting called. +void * +operator new(std::size_t count) +{ + return &global_new_buf; +} + +// A custom allocator +void * +operator new(std::size_t count, const new_tag_t &) +{ + return &tagged_new_buf; +} + int main() { Struct s1, s2, s3; s1.value = 3; |