From 1d1257b95e7011f5d9621b43aafd45bd87fbc34a Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 25 Oct 2005 11:55:31 +0000 Subject: [PATCH] * src/SDCCast.c (addCast): added promotion for bit variables (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 | 6 ++++++ src/SDCCast.c | 25 ++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97e4a194..e25203ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-10-25 Bernhard Held + + * 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 * src/SDCCicode.c (ast2iCode): reverted to 1.224 because of regression: diff --git a/src/SDCCast.c b/src/SDCCast.c index 7f94a700..bb5a75c4 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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)); -- 2.30.2