X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCast.c;h=01411dbed977c25706b3c4da9ce598b706503277;hb=0ddac837e50a0bcf1e3ddf35542eb65a8c158020;hp=bb5a75c4909c6d4805bb36e37054e9f2be427d42;hpb=1d1257b95e7011f5d9621b43aafd45bd87fbc34a;p=fw%2Fsdcc 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;