From: bernhardheld Date: Tue, 25 Oct 2005 13:41:41 +0000 (+0000) Subject: * src/SDCCast.c (decorateType): fixed previouse immature commit, added optimisation X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=0ddac837e50a0bcf1e3ddf35542eb65a8c158020;hp=1d1257b95e7011f5d9621b43aafd45bd87fbc34a;p=fw%2Fsdcc * src/SDCCast.c (decorateType): fixed previouse immature commit, added optimisation (optimizeGetWord): fix warning 'i' might be used uninitialized * src/mcs51/gen.c (genCpl): removed W_COMPLEMENT * src/ds390/gen.c (genCpl): removed W_COMPLEMENT git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3909 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index e25203ee..2c55b617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,10 @@ * src/SDCCast.c (addCast): added promotion for bit variables (decorateType): emit W_COMPLEMENT before the problem vanishes behind - promotion casts + promotion casts + optimisation + (optimizeGetWord): fix warning 'i' might be used uninitialized + * src/mcs51/gen.c (genCpl): removed W_COMPLEMENT + * src/ds390/gen.c (genCpl): removed W_COMPLEMENT 2005-10-24 Bernhard Held diff --git a/src/SDCCast.c b/src/SDCCast.c index bb5a75c4..01411dbe 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3422,9 +3422,23 @@ 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); + + if (resultType == RESULT_TYPE_BIT && + IS_UNSIGNED (tree->left->etype) && + getSize (tree->left->etype) < INTSIZE) + { + /* promotion rules are responsible for this strange result: + bit -> int -> ~int -> bit + uchar -> int -> ~int -> bit + */ + werror(W_COMPLEMENT); + + /* optimize bit-result, even if we optimize a buggy source */ + tree->type = EX_VALUE; + tree->opval.val = constVal ("1"); + } + else + tree->left = addCast (tree->left, resultType, TRUE); LRVAL (tree) = 1; COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)); return tree; @@ -5110,7 +5124,7 @@ optimizeGetByte (ast * tree, RESULT_TYPE resultType) ast * optimizeGetWord (ast * tree, RESULT_TYPE resultType) { - unsigned int i; + unsigned int i = 0; ast * expr; ast * count = NULL; diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 3cdc68ba..050020da 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -1930,7 +1930,6 @@ genCpl (iCode * ic) bit -> int -> ~int -> bit uchar -> int -> ~int -> bit */ - werror(W_COMPLEMENT); emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir); goto release; } diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 085333af..76eb50f8 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -1803,7 +1803,6 @@ genCpl (iCode * ic) bit -> int -> ~int -> bit uchar -> int -> ~int -> bit */ - werror(W_COMPLEMENT); emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir); goto release; }