]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCast.c (addCast): added more promotion fixes
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 27 Jan 2004 13:27:18 +0000 (13:27 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 27 Jan 2004 13:27:18 +0000 (13:27 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3153 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c

index 979dcfe225868fb1da8d4f06c920330caf1c503f..55cfd9d29e298353f3a53d569b866726f7a282e2 100644 (file)
@@ -2030,9 +2030,18 @@ static void
 addCast (ast **tree, RESULT_TYPE resultType, bool upcast)
 {
   sym_link *newLink;
+  bool upCasted = FALSE;
   
   switch (resultType)
     {
+      case RESULT_TYPE_NONE:
+       /* char: promote to int */
+       if (!upcast ||
+           getSize ((*tree)->etype) >= INTSIZE)
+         return;
+       newLink = newIntLink();
+       upCasted = TRUE;
+       break;
       case RESULT_TYPE_CHAR:
        if (getSize ((*tree)->etype) <= 1)
          return;
@@ -2051,22 +2060,26 @@ addCast (ast **tree, RESULT_TYPE resultType, bool upcast)
            getSize ((*tree)->etype) >= INTSIZE)
          return;
        newLink = newIntLink();
+       upCasted = TRUE;
        break;
       case RESULT_TYPE_OTHER:
        if (!upcast)
          return;
-        /* long, float: promote to int */
+        /* return type is long, float: promote char to int */
        if (getSize ((*tree)->etype) >= INTSIZE)
          return;
        newLink = newIntLink();
+       upCasted = TRUE;
        break;
       default:
        return;
     }
   (*tree)->decorated = 0;
   *tree = newNode (CAST, newAst_LINK (newLink), *tree);
-  /* keep unsigned type */
-  SPEC_USIGN ((*tree)->left->opval.lnk) = IS_UNSIGNED ((*tree)->right->etype) ? 1 : 0;
+  /* keep unsigned type during cast to smaller type,
+     but not when promoting from char to int */
+  if (!upCasted)
+    SPEC_USIGN ((*tree)->left->opval.lnk) = IS_UNSIGNED ((*tree)->right->etype) ? 1 : 0;
   *tree = decorateType (*tree, resultType);
 }