* src/SDCCast.c (decorateType): fixed bug 1368489
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 29 Nov 2005 08:55:39 +0000 (08:55 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 29 Nov 2005 08:55:39 +0000 (08:55 +0000)
* support/Util/SDCCerr.c,
* support/Util/SDCCerr.h: added warning W_CMP_SU_CHAR

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

ChangeLog
src/SDCCast.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h
support/regression/tests/onebyte.c

index 34e303af78242abc9b019a0ab834811f3fe202d4..4079dd17d3f2327218a2a73ffaeec5a69fd06f29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-29 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/SDCCast.c (decorateType): fixed bug 1368489
+       * support/Util/SDCCerr.c,
+       * support/Util/SDCCerr.h: added warning W_CMP_SU_CHAR
+
 2005-11-28 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
 
        * device/include/mcs51/at89c51snd1c.h: added file submitted by 
index 83214a5abd2442bc0fe828f85cde3d527e8ceea6..09b4a28c66a5e39edee719bf1ff88f80b82961f3 100644 (file)
@@ -3932,6 +3932,16 @@ decorateType (ast * tree, RESULT_TYPE resultType)
                                    tree->opval.val->type);
           return tree;
         }
+      /* if one is 'signed char ' and the other one is 'unsigned char' */
+      /* it's necessary to promote to int */
+      if (IS_CHAR (RTYPE (tree)) && IS_CHAR (LTYPE (tree)) &&
+          (IS_UNSIGNED (RTYPE (tree)) != IS_UNSIGNED (LTYPE (tree))))
+        {
+          werror (W_CMP_SU_CHAR);
+          tree->left  = addCast (tree->left , RESULT_TYPE_INT, TRUE);
+          tree->right = addCast (tree->right, RESULT_TYPE_INT, TRUE);
+        }
+
       LRVAL (tree) = RRVAL (tree) = 1;
       TTYPE (tree) = TETYPE (tree) = newCharLink ();
       return tree;
index 65cd91ec6095913d5296b2dc257e5746d0ae3c3c..ea38e287d427bc07106c6ff5b457024366a2d9e2 100644 (file)
@@ -422,6 +422,8 @@ struct
    "Both banked and callee-saves cannot be used together." },
 { W_INVALID_INT_CONST, ERROR_LEVEL_WARNING,
    "integer constant '%s' out of range, truncated to %.0lf." },
+{ W_CMP_SU_CHAR, ERROR_LEVEL_PEDANTIC,
+   "comparison of 'signed char' with 'unsigned char' requires promotion to int" },
 };
 
 /*
index 0859facbb378b79133ae5c5d2eb52e330d4c1c12..b48e0b624eb29f36c7e53755160cc345fe449516 100644 (file)
@@ -200,6 +200,7 @@ SDCCERR - SDCC Standard error handler
 #define W_SFR_ABSRANGE                182 /* sfr at address out of range */
 #define E_BANKED_WITH_CALLEESAVES     183 /* banked and callee-saves mixed */
 #define W_INVALID_INT_CONST           184 /* invalid integer literal string */
+#define W_CMP_SU_CHAR                 185 /* comparison of 'signed char' with 'unsigned char' requires promotion to int */
 
 #define MAX_ERROR_WARNING             256 /* size of disable warnings array */
 
index 7f4e2fbbc368fde70dd8d7ca8e498b400c4e28b3..a6ffc9d192059c76b772f5234f5c6cf6fc484881 100644 (file)
@@ -186,3 +186,20 @@ testComplement(void)
   ASSERT(~ (char)          0x80 == (short) 0x007f); ASSERT(~ (char)          0x80 > 0);
   ASSERT(~ (unsigned char) 0x80 == (short) 0xff7f); ASSERT(~ (unsigned char) 0x80 < 0);
 }
+
+void
+testComp(void)
+{
+  {attrL}   signed char  c;
+  {attrR} unsigned char uc;
+
+   c = 0x80; /* -128 */
+  uc = 0x80; /* +128 */
+
+  ASSERT(!(c == uc));
+  ASSERT(  c != uc );
+  ASSERT(  c <  uc );
+  ASSERT(  c <= uc );
+  ASSERT(!(c >  uc));
+  ASSERT(!(c >= uc));
+}