[Lldb-commits] [lldb] r335114 - IRInterpreter: fix sign extension of small types (pr37840)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 20 03:45:29 PDT 2018


Author: labath
Date: Wed Jun 20 03:45:29 2018
New Revision: 335114

URL: http://llvm.org/viewvc/llvm-project?rev=335114&view=rev
Log:
IRInterpreter: fix sign extension of small types (pr37840)

Sign-extension of small types (e.g. short) was not handled correctly.
The reason for that was that when we were assigning the a value to the
Scalar object, we would accidentally promote the type to int (even
though the assignment code in AssignTypeToMatch tried to cast the value
to the appropriate type, it would still invoke the "int" version of
operator=). Instead, I use the APInt version of operator=, where the
bitwidth is specified explicitly. Among other things, this allows us to
fold the individual size cases into one.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py
    lldb/trunk/source/Expression/IRInterpreter.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py?rev=335114&r1=335113&r2=335114&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py Wed Jun 20 03:45:29 2018
@@ -17,6 +17,7 @@ from lldbsuite.test import lldbutil
 class IRInterpreterTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
+    NO_DEBUG_INFO_TESTCASE = True
 
     def setUp(self):
         # Call super's setUp().
@@ -85,3 +86,10 @@ class IRInterpreterTestCase(TestBase):
                 jit_result,
                 "While evaluating " +
                 expression)
+
+    def test_type_conversions(self):
+        target = self.dbg.GetDummyTarget()
+        short_val = target.EvaluateExpression("(short)-1")
+        self.assertEqual(short_val.GetValueAsSigned(), -1)
+        long_val = target.EvaluateExpression("(long) "+ short_val.GetName())
+        self.assertEqual(long_val.GetValueAsSigned(), -1)

Modified: lldb/trunk/source/Expression/IRInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=335114&r1=335113&r2=335114&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRInterpreter.cpp (original)
+++ lldb/trunk/source/Expression/IRInterpreter.cpp Wed Jun 20 03:45:29 2018
@@ -154,16 +154,10 @@ public:
 
     switch (type_size) {
     case 1:
-      scalar = (uint8_t)u64value;
-      break;
     case 2:
-      scalar = (uint16_t)u64value;
-      break;
     case 4:
-      scalar = (uint32_t)u64value;
-      break;
     case 8:
-      scalar = (uint64_t)u64value;
+      scalar = llvm::APInt(type_size*8, u64value);
       break;
     default:
       return false;




More information about the lldb-commits mailing list