From 90d099cc63ac1e31d4ea80b0e96307d76df65813 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 27 Jan 2004 13:27:18 +0000 Subject: [PATCH] * src/SDCCast.c (addCast): added more promotion fixes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3153 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index 979dcfe2..55cfd9d2 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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); } -- 2.47.2