Fixed a bug in operandOperation, should not uncoditionally cast to
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 May 2001 04:12:11 +0000 (04:12 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 May 2001 04:12:11 +0000 (04:12 +0000)
unsigned long

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@815 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCicode.c

index 3731ecb730d7e8fecdb8df2d78a154edf9a1e01a..7a6f05055cfd8ffe3e409fe540f7b72c765152c5 100644 (file)
@@ -838,11 +838,15 @@ operand *
 operandOperation (operand * left, operand * right,
                  int op, sym_link * type)
 {
+  sym_link *let , *ret;
   operand *retval = (operand *) 0;
-
+  
   assert (isOperandLiteral (left));
-  if (right)
+  let = getSpec(operandType(left));
+  if (right) {
     assert (isOperandLiteral (right));
+    ret = getSpec(operandType(left));
+  }
 
   switch (op)
     {
@@ -874,22 +878,34 @@ operandOperation (operand * left, operand * right,
                                                   operandLitValue (right)));
       break;
     case '%':
-      if ((unsigned long) operandLitValue (right) == 0)
-       {
+      if ((unsigned long) operandLitValue (right) == 0) {
          werror (E_DIVIDE_BY_ZERO);
          retval = right;
-       }
-      else
-       retval = operandFromLit ((unsigned long) operandLitValue (left) %
-                                (unsigned long) operandLitValue (right));
+      }
+      else 
+       retval = operandFromLit ((SPEC_USIGN(let) ? 
+                                 (unsigned long) operandLitValue (left) :
+                                 (long) operandLitValue (left)) %
+                                (SPEC_USIGN(ret) ? 
+                                 (unsigned long) operandLitValue (right) :
+                                 (long) operandLitValue (right)));
+
       break;
     case LEFT_OP:
-      retval = operandFromLit ((unsigned long) operandLitValue (left) <<
-                              (unsigned long) operandLitValue (right));
+      retval = operandFromLit (((SPEC_USIGN(let) ? 
+                                 (unsigned long) operandLitValue (left) :
+                                 (long) operandLitValue (left)) <<
+                                (SPEC_USIGN(ret) ? 
+                                 (unsigned long) operandLitValue (right) :
+                                 (long) operandLitValue (right))));
       break;
     case RIGHT_OP:
-      retval = operandFromLit ((unsigned long) operandLitValue (left) >>
-                              (unsigned long) operandLitValue (right));
+      retval = operandFromLit (((SPEC_USIGN(let) ? 
+                                 (unsigned long) operandLitValue (left) :
+                                 (long) operandLitValue (left)) >>
+                                (SPEC_USIGN(ret) ? 
+                                 (unsigned long) operandLitValue (right) :
+                                 (long) operandLitValue (right))));
       break;
     case EQ_OP:
       retval = operandFromLit (operandLitValue (left) ==