From 5be90381bf67a833edd640da0d67400b3bb0f111 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 29 Nov 2005 08:55:39 +0000 Subject: [PATCH] * src/SDCCast.c (decorateType): fixed bug 1368489 * 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 | 6 ++++++ src/SDCCast.c | 10 ++++++++++ support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + support/regression/tests/onebyte.c | 17 +++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/ChangeLog b/ChangeLog index 34e303af..4079dd17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-11-29 Bernhard Held + + * 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 * device/include/mcs51/at89c51snd1c.h: added file submitted by diff --git a/src/SDCCast.c b/src/SDCCast.c index 83214a5a..09b4a28c 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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; diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 65cd91ec..ea38e287 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 0859facb..b48e0b62 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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 */ diff --git a/support/regression/tests/onebyte.c b/support/regression/tests/onebyte.c index 7f4e2fbb..a6ffc9d1 100644 --- a/support/regression/tests/onebyte.c +++ b/support/regression/tests/onebyte.c @@ -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)); +} -- 2.30.2