X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=30503b61f5a8c5dee33bc785ad3044f7186cd730;hb=47bb725c96ea3f78ac860012cf1feb35cf66bfb2;hp=e24cc39564a7fd32665db75ce2bdd0255ad71083;hpb=6ea371e5f59c6d38aaa2070e2fc39cf300328fb9;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index e24cc395..30503b61 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2410,11 +2410,7 @@ geniCodeAdd (operand * left, operand * right, RESULT_TYPE resultType, int lvl) size = operandFromLit (getSize (ltype->next)); SPEC_USIGN (getSpec (operandType (size))) = 1; indexUnsigned = IS_UNSIGNED (getSpec (operandType (right))); - right = geniCodeMultiply (right, - size, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR); + right = geniCodeMultiply (right, size, resultType); /* Even if right is a 'unsigned char', the result will be a 'signed int' due to the promotion rules. It doesn't make sense when accessing arrays, so let's fix it here: */ @@ -2513,6 +2509,14 @@ geniCodeArray (operand * left, operand * right, int lvl) operand *size; sym_link *ltype = operandType (left); bool indexUnsigned; + RESULT_TYPE resultType; + + resultType = (getArraySizePtr(left) >= INTSIZE) ? RESULT_TYPE_INT : RESULT_TYPE_CHAR; + if (DCL_ELEM (ltype)) + { + if (DCL_ELEM (ltype) * getSize (ltype->next) <= 255) + resultType = RESULT_TYPE_CHAR; + } if (IS_PTR (ltype)) { @@ -2521,22 +2525,13 @@ geniCodeArray (operand * left, operand * right, int lvl) left = geniCodeRValue (left, FALSE); } - return geniCodeDerefPtr (geniCodeAdd (left, - right, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR, - lvl), + return geniCodeDerefPtr (geniCodeAdd (left, right, resultType, lvl), lvl); } size = operandFromLit (getSize (ltype->next)); SPEC_USIGN (getSpec (operandType (size))) = 1; indexUnsigned = IS_UNSIGNED (getSpec (operandType (right))); - right = geniCodeMultiply (right, - size, - (getArraySizePtr(left) >= INTSIZE) ? - RESULT_TYPE_INT : - RESULT_TYPE_CHAR); + right = geniCodeMultiply (right, size, resultType); /* Even if right is a 'unsigned char', the result will be a 'signed int' due to the promotion rules. It doesn't make sense when accessing arrays, so let's fix it here: */ if (indexUnsigned)