diff options
-rw-r--r-- | lldb/include/lldb/Core/Scalar.h | 3 | ||||
-rw-r--r-- | lldb/source/Core/Scalar.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Expression/IRInterpreter.cpp | 12 | ||||
-rw-r--r-- | lldb/test/expression_command/persistent_variables/TestPersistentVariables.py | 10 |
4 files changed, 42 insertions, 5 deletions
diff --git a/lldb/include/lldb/Core/Scalar.h b/lldb/include/lldb/Core/Scalar.h index 2a89a598b5a..821a0fb1ae2 100644 --- a/lldb/include/lldb/Core/Scalar.h +++ b/lldb/include/lldb/Core/Scalar.h @@ -102,6 +102,9 @@ public: bool Cast (Scalar::Type type); + + bool + MakeSigned (); static const char * GetValueTypeAsCString (Scalar::Type value_type); diff --git a/lldb/source/Core/Scalar.cpp b/lldb/source/Core/Scalar.cpp index 16d8230cdef..e0a9624805e 100644 --- a/lldb/source/Core/Scalar.cpp +++ b/lldb/source/Core/Scalar.cpp @@ -715,6 +715,28 @@ Scalar::Cast(Scalar::Type type) return success; } +bool +Scalar::MakeSigned () +{ + bool success = false; + + switch (m_type) + { + case e_void: break; + case e_sint: success = true; break; + case e_uint: m_type = e_sint; success = true; break; + case e_slong: success = true; break; + case e_ulong: m_type = e_slong; success = true; break; + case e_slonglong: success = true; break; + case e_ulonglong: m_type = e_slonglong; success = true; break; + case e_float: success = true; break; + case e_double: success = true; break; + case e_long_double: success = true; break; + } + + return success; +} + int Scalar::SInt(int fail_value) const { diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index b3c35bf8e9a..5986ebb4a00 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -662,12 +662,16 @@ IRInterpreter::Interpret (llvm::Module &module, result = L - R; break; case Instruction::SDiv: + L.MakeSigned(); + R.MakeSigned(); result = L / R; break; case Instruction::UDiv: result = L.GetRawBits64(0) / R.GetRawBits64(1); break; case Instruction::SRem: + L.MakeSigned(); + R.MakeSigned(); result = L % R; break; case Instruction::URem: @@ -1004,15 +1008,23 @@ IRInterpreter::Interpret (llvm::Module &module, result = (L.GetRawBits64(0) <= R.GetRawBits64(0)); break; case CmpInst::ICMP_SGT: + L.MakeSigned(); + R.MakeSigned(); result = (L > R); break; case CmpInst::ICMP_SGE: + L.MakeSigned(); + R.MakeSigned(); result = (L >= R); break; case CmpInst::ICMP_SLT: + L.MakeSigned(); + R.MakeSigned(); result = (L < R); break; case CmpInst::ICMP_SLE: + L.MakeSigned(); + R.MakeSigned(); result = (L <= R); break; } diff --git a/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py b/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py index 51c22aa9c52..fbbbda620de 100644 --- a/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py +++ b/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py @@ -28,24 +28,24 @@ class PersistentVariablesTestCase(TestBase): self.expect("expression $i + 1", startstr = "(int) $1 = 6") - # (int) $0 = 6 self.expect("expression $i + 3", startstr = "(int) $2 = 8") - # (int) $1 = 8 self.expect("expression $2 + $1", startstr = "(int) $3 = 14") - # (int) $2 = 14 self.expect("expression $3", startstr = "(int) $3 = 14") - # (int) $2 = 14 self.expect("expression $2", startstr = "(int) $2 = 8") - # (int) $1 = 8 + self.expect("expression (int)-2", + startstr = "(int) $4 = -2") + + self.expect("expression $4 > (int)31", + startstr = "(bool) $5 = false") if __name__ == '__main__': import atexit |