* src/SDCCast.c (processParams): added new type flow and restructured
[fw/sdcc] / src / SDCCval.c
index fdb2c4be0a491999e3aedde062033bc193951a18..a0d5e15c31b90aebdb88f2112aaf271fa3f8812e 100644 (file)
@@ -119,7 +119,7 @@ convertIListToConstList(initList *src, literalList **lList)
            return FALSE;
        }
 
-       if (!IS_AST_LIT_VALUE(decorateType(resolveSymbols(iLoop->init.node))))
+       if (!IS_AST_LIT_VALUE(decorateType(resolveSymbols(iLoop->init.node), RESULT_CHECK)))
        {
            return FALSE;
        }
@@ -268,19 +268,28 @@ list2expr (initList * ilist)
 /*------------------------------------------------------------------*/
 /* resolveIvalSym - resolve symbols in initial values               */
 /*------------------------------------------------------------------*/
-void 
-resolveIvalSym (initList * ilist)
+void
+resolveIvalSym (initList * ilist, sym_link * type)
 {
+  RESULT_TYPE resultType;
+
   if (!ilist)
     return;
 
   if (ilist->type == INIT_NODE)
-    ilist->init.node = decorateType (resolveSymbols (ilist->init.node));
+    {
+      if (IS_PTR (type))
+        resultType = RESULT_TYPE_NONE;
+      else
+        resultType = getResultTypeFromType (getSpec (type));
+      ilist->init.node = decorateType (resolveSymbols (ilist->init.node),
+                                      resultType);
+    }
 
   if (ilist->type == INIT_DEEP)
-    resolveIvalSym (ilist->init.deep);
+    resolveIvalSym (ilist->init.deep, type);
 
-  resolveIvalSym (ilist->next);
+  resolveIvalSym (ilist->next, type);
 }
 
 /*-----------------------------------------------------------------*/
@@ -374,7 +383,10 @@ static value *cheapestVal (value *val) {
 
 static value *cheapestVal (value *val)
 {
-  /* - signed/unsigned must no be changed.
+  if (IS_FLOAT (val->type) || IS_CHAR (val->type))
+    return val;
+
+  /* - signed/unsigned must not be changed.
      - long must not be changed.
 
      the only possible reduction is from signed int to signed char,
@@ -386,18 +398,17 @@ static value *cheapestVal (value *val)
       !SPEC_USIGN(val->type) &&
       !SPEC_LONG(val->type) &&
       SPEC_CVAL(val->type).v_int >= -128 &&
-      SPEC_CVAL(val->type).v_int <=  127)
+      SPEC_CVAL(val->type).v_int <     0)
 
     {
       SPEC_NOUN(val->type) = V_CHAR;
     }
-  /* this could be too aggressive:
-     'unsigned char' promotes to 'signed int', so that we can
+  /* 'unsigned char' promotes to 'signed int', so that we can
      reduce it the other way */
   if (IS_INT(val->type) &&
       !SPEC_USIGN(val->type) &&
       !SPEC_LONG(val->type) &&
-      SPEC_CVAL(val->type).v_int >= 128 &&
+      SPEC_CVAL(val->type).v_int >=   0 &&
       SPEC_CVAL(val->type).v_int <= 255)
 
     {
@@ -523,19 +534,8 @@ value *constVal (char *s)
                                     the programer wants */
       SPEC_NOUN (val->type) = V_INT;
     }
-    else if (dval>0x7f && !SPEC_USIGN (val->type)) { // check if we have to promote to int
-#if 0
-      if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */
-          dval<=0xff) {
-        SPEC_USIGN (val->type) = 1;
-      } else {
-       SPEC_NOUN (val->type) = V_INT;
-      }
-#else
-      /* this is quite agressive: 'unsigned char' will be promoted to 'signed int',
-         so that the signedness of a char shouldn't matter */
+    else { /* store char's always as unsigned; this helps other optimizations */
       SPEC_USIGN (val->type) = 1;
-#endif
     }
     if (dval>0xffff && SPEC_USIGN (val->type)) { // check if we have to promote to long
       SPEC_LONG (val->type) = 1;
@@ -1088,18 +1088,9 @@ valMult (value * lval, value * rval)
                           IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
   SPEC_SCLS  (val->type) = S_LITERAL;  /* will remain literal */
   SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  /* both signed char and unsigned char are promoted to signed int */
-  if (IS_CHAR (lval->etype))
-    {
-      SPEC_USIGN (lval->etype) = 0;
-      SPEC_NOUN  (lval->etype) = V_INT;
-    }
-  if (IS_CHAR (rval->etype))
-    {
-      SPEC_USIGN (rval->etype) = 0;
-      SPEC_NOUN  (rval->etype) = V_INT;
-    }
-  SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype));
+  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
+                                                   rval->etype,
+                                                   TRUE));
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) * floatFromVal (rval);
       /* signed and unsigned mul are the same, as long as the precision of the
@@ -1107,27 +1098,25 @@ valMult (value * lval, value * rval)
   else if (SPEC_LONG (val->type))
     SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) *
                                    (TYPE_UDWORD) floatFromVal (rval);
-  else if (SPEC_USIGN (val->type)) /* unsigned */
+  else if (SPEC_USIGN (val->type)) /* unsigned int */
     {
       TYPE_UDWORD ul = (TYPE_UWORD) floatFromVal (lval) *
                        (TYPE_UWORD) floatFromVal (rval);
 
       SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) ul;
-      if (!options.lessPedantic &&
-          ul != (TYPE_UWORD) ul)
+      if (ul != (TYPE_UWORD) ul)
         werror (W_INT_OVL);
     }
-  else /* int */
+  else /* signed int */
     {
       TYPE_DWORD l = (TYPE_WORD) floatFromVal (lval) *
                      (TYPE_WORD) floatFromVal (rval);
 
       SPEC_CVAL (val->type).v_int = (TYPE_WORD) l;
-      if (!options.lessPedantic &&
-          l != (TYPE_WORD) l)
+      if (l != (TYPE_WORD) l)
         werror (W_INT_OVL);
     }
-  return cheapestVal(val);
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1150,45 +1139,32 @@ valDiv (value * lval, value * rval)
   SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
                           IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
   SPEC_SCLS (val->etype) = S_LITERAL;
-  /* both signed char and unsigned char are promoted to signed int */
-  if (IS_CHAR (lval->etype))
-    {
-      SPEC_USIGN (lval->etype) = 0;
-      SPEC_NOUN  (lval->etype) = V_INT;
-    }
-  if (IS_CHAR (rval->etype))
-    {
-      SPEC_USIGN (rval->etype) = 0;
-      SPEC_NOUN  (rval->etype) = V_INT;
-    }
-  SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype));
   SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
+  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
+                                                   rval->etype,
+                                                   TRUE));
 
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) / floatFromVal (rval);
+  else if (SPEC_LONG (val->type))
+    {
+      if (SPEC_USIGN (val->type))
+       SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) /
+         (TYPE_UDWORD) floatFromVal (rval);
+      else
+       SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) /
+         (TYPE_DWORD) floatFromVal (rval);
+    }
   else
     {
-      if (SPEC_LONG (val->type))
-       {
-         if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) /
-             (TYPE_UDWORD) floatFromVal (rval);
-         else
-           SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) /
-             (TYPE_DWORD) floatFromVal (rval);
-       }
+      if (SPEC_USIGN (val->type))
+        SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) /
+          (TYPE_UWORD) floatFromVal (rval);
       else
-       {
-         if (SPEC_USIGN (val->type)) {
-           SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) /
-             (TYPE_UWORD) floatFromVal (rval);
-         } else {
-           SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) /
-             (TYPE_WORD) floatFromVal (rval);
-         }
-       }
+        SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) /
+          (TYPE_WORD) floatFromVal (rval);
     }
-  return cheapestVal(val);
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1204,8 +1180,10 @@ valMod (value * lval, value * rval)
   val->type = val->etype = newLink (SPECIFIER);
   SPEC_NOUN (val->type) = V_INT;       /* type is int */
   SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
-  SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype));
   SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
+  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
+                                                   rval->etype,
+                                                   TRUE));
 
   if (SPEC_LONG (val->type))
     {
@@ -1218,16 +1196,14 @@ valMod (value * lval, value * rval)
     }
   else
     {
-      if (SPEC_USIGN (val->type)) {
-       SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) %
-         (TYPE_UWORD) floatFromVal (rval);
-      } else {
-       SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) %
-         (TYPE_WORD) floatFromVal (rval);
-      }
+      if (SPEC_USIGN (val->type))
+        SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) %
+          (TYPE_UWORD) floatFromVal (rval);
+      else
+        SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) %
+          (TYPE_WORD) floatFromVal (rval);
     }
-
-  return cheapestVal(val);
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1245,30 +1221,30 @@ valPlus (value * lval, value * rval)
                           IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
   SPEC_SCLS  (val->type) = S_LITERAL;  /* will remain literal */
   SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  /* both signed char and unsigned char are promoted to signed int */
-  if (IS_CHAR (lval->etype))
-    {
-      SPEC_USIGN (lval->etype) = 0;
-      SPEC_NOUN  (lval->etype) = V_INT;
-    }
-  if (IS_CHAR (rval->etype))
-    {
-      SPEC_USIGN (rval->etype) = 0;
-      SPEC_NOUN  (rval->etype) = V_INT;
-    }
-  SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype));
+  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
+                                                   rval->etype,
+                                                   TRUE));
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval);
+  else  if (SPEC_LONG (val->type))
+    {
+      if (SPEC_USIGN (val->type))
+        SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) +
+         (TYPE_UDWORD) floatFromVal (rval);
+      else
+        SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) +
+          (TYPE_DWORD) floatFromVal (rval);
+    }
   else
     {
       if (SPEC_USIGN (val->type))
-       SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) +
-         (TYPE_UDWORD) floatFromVal (rval);
+        SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) +
+          (TYPE_UWORD) floatFromVal (rval);
       else
-       SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) +
-         (TYPE_DWORD) floatFromVal (rval);
+        SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) +
+          (TYPE_WORD) floatFromVal (rval);
     }
-  return cheapestVal(val);
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1286,30 +1262,30 @@ valMinus (value * lval, value * rval)
                           IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
   SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
   SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  /* both signed char and unsigned char are promoted to signed int */
-  if (IS_CHAR (lval->etype))
-    {
-      SPEC_USIGN (lval->etype) = 0;
-      SPEC_NOUN  (lval->etype) = V_INT;
-    }
-  if (IS_CHAR (rval->etype))
-    {
-      SPEC_USIGN (rval->etype) = 0;
-      SPEC_NOUN  (rval->etype) = V_INT;
-    }
-  SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype));
+  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
+                                                   rval->etype,
+                                                   TRUE));
   if (IS_FLOAT (val->type))
-    SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval);
-  else
+    SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval);
+  else  if (SPEC_LONG (val->type))
     {
       if (SPEC_USIGN (val->type))
-       SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) -
-         (TYPE_UDWORD) floatFromVal (rval);
+        SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) -
+          (TYPE_UDWORD) floatFromVal (rval);
       else
-       SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) -
-         (TYPE_DWORD) floatFromVal (rval);
+        SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) -
+          (TYPE_DWORD) floatFromVal (rval);
     }
-  return cheapestVal(val);
+  else
+   {
+     if (SPEC_USIGN (val->type))
+       SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) -
+         (TYPE_UWORD) floatFromVal (rval);
+     else
+       SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) -
+         (TYPE_WORD) floatFromVal (rval);
+    }
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1330,19 +1306,46 @@ valShift (value * lval, value * rval, int lr)
     SPEC_USIGN (val->type) = SPEC_USIGN (lval->etype);
   SPEC_LONG (val->type) = SPEC_LONG (lval->etype);
 
-  if (SPEC_USIGN (val->type))
+  if (getSize (val->type) * 8 <= (TYPE_UDWORD) floatFromVal (rval) &&
+       /* left shift */
+      (lr ||
+       /* right shift and unsigned */
+       (!lr && SPEC_USIGN (rval->type))))
     {
-      SPEC_CVAL (val->type).v_ulong = lr ?
-       (TYPE_UDWORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
-       (TYPE_UDWORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+      werror (W_SHIFT_CHANGED, (lr ? "left" : "right"));
+    }
+
+  if (SPEC_LONG (val->type))
+    {
+      if (SPEC_USIGN (val->type))
+        {
+          SPEC_CVAL (val->type).v_ulong = lr ?
+           (TYPE_UDWORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
+           (TYPE_UDWORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+        }
+      else
+        {
+          SPEC_CVAL (val->type).v_long = lr ?
+           (TYPE_DWORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
+           (TYPE_DWORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+        }
     }
   else
     {
-      SPEC_CVAL (val->type).v_long = lr ?
-       (TYPE_DWORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
-       (TYPE_DWORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+      if (SPEC_USIGN (val->type))
+        {
+          SPEC_CVAL (val->type).v_uint = lr ?
+           (TYPE_UWORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
+           (TYPE_UWORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+        }
+      else
+        {
+          SPEC_CVAL (val->type).v_int = lr ?
+           (TYPE_WORD) floatFromVal (lval) << (TYPE_UDWORD) floatFromVal (rval) : \
+           (TYPE_WORD) floatFromVal (lval) >> (TYPE_UDWORD) floatFromVal (rval);
+        }
     }
-  return cheapestVal(val);
+  return cheapestVal (val);
 }
 
 /*------------------------------------------------------------------*/
@@ -1391,17 +1394,18 @@ valCompare (value * lval, value * rval, int ctype)
          TYPE_UDWORD l, r;
 
          l = (TYPE_UDWORD) floatFromVal (lval);
-         if (SPEC_NOUN(lval->type) == V_CHAR)
-           l &= 0xffff; /* promote to int */
-         else if (!SPEC_LONG (lval->type))
-           l &= 0xffff;
-
          r = (TYPE_UDWORD) floatFromVal (rval);
-         if (SPEC_NOUN(rval->type) == V_CHAR)
-           r &= 0xffff; /* promote to int */
-         else if (!SPEC_LONG (rval->type))
-           r &= 0xffff;
-
+         /* In order to correctly compare 'signed int' and 'unsigned int' it's
+            neccessary to strip them to 16 bit.
+            Literals are reduced to their cheapest type, therefore left and
+            right might have different types. It's neccessary to find a
+            common type: int (used for char too) or long */
+         if (!IS_LONG (lval->etype) &&
+             !IS_LONG (rval->etype))
+           {
+             r = (TYPE_UWORD) r;
+             l = (TYPE_UWORD) l;
+           }
          SPEC_CVAL (val->type).v_int = l == r;
        }
       break;
@@ -1417,17 +1421,18 @@ valCompare (value * lval, value * rval, int ctype)
          TYPE_UDWORD l, r;
 
          l = (TYPE_UDWORD) floatFromVal (lval);
-         if (SPEC_NOUN(lval->type) == V_CHAR)
-           l &= 0xffff; /* promote to int */
-         else if (!SPEC_LONG (lval->type))
-           l &= 0xffff;
-
          r = (TYPE_UDWORD) floatFromVal (rval);
-         if (SPEC_NOUN(rval->type) == V_CHAR)
-           r &= 0xffff; /* promote to int */
-         else if (!SPEC_LONG (rval->type))
-           r &= 0xffff;
-
+         /* In order to correctly compare 'signed int' and 'unsigned int' it's
+            neccessary to strip them to 16 bit.
+            Literals are reduced to their cheapest type, therefore left and
+            right might have different types. It's neccessary to find a
+            common type: int (used for char too) or long */
+         if (!IS_LONG (lval->etype) &&
+             !IS_LONG (rval->etype))
+           {
+             r = (TYPE_UWORD) r;
+             l = (TYPE_UWORD) l;
+           }
          SPEC_CVAL (val->type).v_int = l != r;
        }
       break;
@@ -1447,9 +1452,9 @@ valBitwise (value * lval, value * rval, int op)
 
   /* create a new value */
   val = newValue ();
-  val->type = copyLinkChain (getSize(rval->type) > getSize(lval->type) ?
-                            rval->type : lval->type);
+  val->type = computeType (lval->etype, rval->etype, FALSE);
   val->etype = getSpec (val->type);
+  SPEC_SCLS (val->etype) = S_LITERAL;
 
   switch (op)
     {
@@ -1457,19 +1462,19 @@ valBitwise (value * lval, value * rval, int op)
       if (SPEC_LONG (val->type))
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) &
-             (unsigned long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) &
+             (TYPE_UDWORD) floatFromVal (rval);
          else
-           SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) &
-             (long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) &
+             (TYPE_DWORD) floatFromVal (rval);
        }
       else
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) &
-             (unsigned) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) &
+             (TYPE_UWORD) floatFromVal (rval);
          else
-           SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) & (int) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) & (TYPE_WORD) floatFromVal (rval);
        }
       break;
 
@@ -1477,20 +1482,20 @@ valBitwise (value * lval, value * rval, int op)
       if (SPEC_LONG (val->type))
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) |
-             (unsigned long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) |
+             (TYPE_UDWORD) floatFromVal (rval);
          else
-           SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) |
-             (long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) |
+             (TYPE_DWORD) floatFromVal (rval);
        }
       else
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) |
-             (unsigned) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) |
+             (TYPE_UWORD) floatFromVal (rval);
          else
            SPEC_CVAL (val->type).v_int =
-             (int) floatFromVal (lval) | (int) floatFromVal (rval);
+             (TYPE_WORD) floatFromVal (lval) | (TYPE_WORD) floatFromVal (rval);
        }
 
       break;
@@ -1499,24 +1504,24 @@ valBitwise (value * lval, value * rval, int op)
       if (SPEC_LONG (val->type))
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) ^
-             (unsigned long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) ^
+             (TYPE_UDWORD) floatFromVal (rval);
          else
-           SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) ^
-             (long) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) ^
+             (TYPE_DWORD) floatFromVal (rval);
        }
       else
        {
          if (SPEC_USIGN (val->type))
-           SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) ^
-             (unsigned) floatFromVal (rval);
+           SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) ^
+             (TYPE_UWORD) floatFromVal (rval);
          else
            SPEC_CVAL (val->type).v_int =
-             (int) floatFromVal (lval) ^ (int) floatFromVal (rval);
+             (TYPE_WORD) floatFromVal (lval) ^ (TYPE_WORD) floatFromVal (rval);
        }
       break;
     }
-
+    
   return cheapestVal(val);
 }
 
@@ -1533,7 +1538,7 @@ valLogicAndOr (value * lval, value * rval, int op)
   val->type = val->etype = newCharLink ();
   val->type->class = SPECIFIER;
   SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
-  SPEC_USIGN (val->type) = 0;
+  SPEC_USIGN (val->type) = 1;
 
   switch (op)
     {