[Lldb-commits] [lldb] r182668 - Fixed signed operations in the IR interpreter.
Sean Callanan
scallanan at apple.com
Fri May 24 13:36:57 PDT 2013
Author: spyffe
Date: Fri May 24 15:36:56 2013
New Revision: 182668
URL: http://llvm.org/viewvc/llvm-project?rev=182668&view=rev
Log:
Fixed signed operations in the IR interpreter.
Scalar now can make itself signed if needed.
<rdar://problem/13977632>
Modified:
lldb/trunk/include/lldb/Core/Scalar.h
lldb/trunk/source/Core/Scalar.cpp
lldb/trunk/source/Expression/IRInterpreter.cpp
lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py
Modified: lldb/trunk/include/lldb/Core/Scalar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Scalar.h?rev=182668&r1=182667&r2=182668&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Scalar.h (original)
+++ lldb/trunk/include/lldb/Core/Scalar.h Fri May 24 15:36:56 2013
@@ -102,6 +102,9 @@ public:
bool
Cast (Scalar::Type type);
+
+ bool
+ MakeSigned ();
static const char *
GetValueTypeAsCString (Scalar::Type value_type);
Modified: lldb/trunk/source/Core/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=182668&r1=182667&r2=182668&view=diff
==============================================================================
--- lldb/trunk/source/Core/Scalar.cpp (original)
+++ lldb/trunk/source/Core/Scalar.cpp Fri May 24 15:36:56 2013
@@ -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
{
Modified: lldb/trunk/source/Expression/IRInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=182668&r1=182667&r2=182668&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRInterpreter.cpp (original)
+++ lldb/trunk/source/Expression/IRInterpreter.cpp Fri May 24 15:36:56 2013
@@ -662,12 +662,16 @@ IRInterpreter::Interpret (llvm::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 &
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;
}
Modified: lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py?rev=182668&r1=182667&r2=182668&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py (original)
+++ lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py Fri May 24 15:36:56 2013
@@ -28,24 +28,24 @@ class PersistentVariablesTestCase(TestBa
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
More information about the lldb-commits
mailing list