/* bitwise or */
/*----------------------------*/
case '|':
- /* if the rewrite succeeds then don't go any furthur */
+ /* if the rewrite succeeds then don't go any further */
{
ast *wtree = optimizeRRCRLC (tree);
if (wtree != tree)
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;
static int
isBitAndPow2 (ast * tree)
{
- int p2;
-
/* if this is not a bit and */
if (!IS_BITAND (tree))
return -1;
if (!IS_AST_LIT_VALUE (tree->right))
return -1;
- if (AST_LIT_VALUE (tree->right) == 1)
- return 0;
- p2 = powof2 ((TYPE_UDWORD)AST_LIT_VALUE (tree->right));
- if (!p2)
- return -1;
-
- return p2;
+ return powof2 ((TYPE_UDWORD)AST_LIT_VALUE (tree->right));
}
/*-----------------------------------------------------------------*/
ast *
optimizeGetWord (ast * tree, RESULT_TYPE resultType)
{
- unsigned int i;
+ unsigned int i = 0;
ast * expr;
ast * count = NULL;
return;
/*------------------------------------------------------------------*/
/*----------------------------*/
- /* compliment */
+ /* complement */
/*----------------------------*/
case '~':
fprintf(outfile,"COMPL (%p) type (",tree);