* src/SDCCast.c (addCast): added promotion for bit variables
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Oct 2005 11:55:31 +0000 (11:55 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Oct 2005 11:55:31 +0000 (11:55 +0000)
(decorateType): emit W_COMPLEMENT before the problem vanishes behind promotion casts

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

ChangeLog
src/SDCCast.c

index 97e4a19401f45f5741111f0515b248a121265057..e25203ee5baf909a9e8126df378db374142bd006 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-25 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/SDCCast.c (addCast): added promotion for bit variables
+       (decorateType): emit W_COMPLEMENT before the problem vanishes behind
+       promotion casts
+
 2005-10-24 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/SDCCicode.c (ast2iCode): reverted to 1.224 because of regression:
index 7f94a70067448bedbe5942d2928187fd42d6075c..bb5a75c4909c6d4805bb36e37054e9f2be427d42 100644 (file)
@@ -2087,7 +2087,7 @@ getResultTypeFromType (sym_link *type)
 /* addCast - adds casts to a type specified by RESULT_TYPE         */
 /*-----------------------------------------------------------------*/
 static ast *
-addCast (ast *tree, RESULT_TYPE resultType, bool upcast)
+addCast (ast *tree, RESULT_TYPE resultType, bool promote)
 {
   sym_link *newLink;
   bool upCasted = FALSE;
@@ -2095,9 +2095,22 @@ addCast (ast *tree, RESULT_TYPE resultType, bool upcast)
   switch (resultType)
     {
       case RESULT_TYPE_NONE:
-        /* char: promote to int */
-        if (!upcast ||
+        /* if thing smaller than int must be promoted to int */
+        if (!promote ||
             getSize (tree->etype) >= INTSIZE)
+          /* promotion not necessary or already an int */
+          return tree;
+        /* char and bits: promote to int */
+        newLink = newIntLink();
+        upCasted = TRUE;
+        break;
+      case RESULT_TYPE_BIT:
+        if (!promote ||
+            /* already an int */
+            bitsForType (tree->etype) >= 16 ||
+            /* bit to bit operation: don't promote, the code generators
+               hopefully know everything about promotion rules */
+            bitsForType (tree->etype) == 1)
           return tree;
         newLink = newIntLink();
         upCasted = TRUE;
@@ -2118,14 +2131,14 @@ addCast (ast *tree, RESULT_TYPE resultType, bool upcast)
           }
 #endif
         /* char: promote to int */
-        if (!upcast ||
+        if (!promote ||
             getSize (tree->etype) >= INTSIZE)
           return tree;
         newLink = newIntLink();
         upCasted = TRUE;
         break;
       case RESULT_TYPE_OTHER:
-        if (!upcast)
+        if (!promote)
           return tree;
         /* return type is long, float: promote char to int */
         if (getSize (tree->etype) >= INTSIZE)
@@ -3409,6 +3422,8 @@ decorateType (ast * tree, RESULT_TYPE resultType)
           TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
           return addCast (tree, resultType, TRUE);
         }
+      if (getSize (tree->left->etype) < INTSIZE)
+        werror(W_COMPLEMENT);
       tree->left = addCast (tree->left, resultType, TRUE);
       LRVAL (tree) = 1;
       COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));