From: kvigor Date: Mon, 20 Nov 2000 23:22:55 +0000 (+0000) Subject: widen array indices to int type before doing other arithmetic X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=f442564d3a974b695a7f6abb24f12223930104a9;p=fw%2Fsdcc widen array indices to int type before doing other arithmetic git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@504 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 36410ad3..874e318c 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1624,9 +1624,12 @@ operand *geniCodeAdd (operand *left, operand *right ) isarray = left->isaddr; size = operandFromLit(getSize(ltype->next)); + if (getSize(ltype) > 1 && (getSize(rtype) < INTSIZE)) + { + right = geniCodeCast(INTTYPE,right,TRUE); + } right = geniCodeMultiply (right ,size); - if (getSize(ltype) > 1) - right = geniCodeCast(INTTYPE,right,TRUE); + resType = copyLinkChain(ltype); } else { /* make them the same size */ @@ -1723,11 +1726,18 @@ operand *geniCodeArray (operand *left,operand *right) if (IS_PTR(ltype)) { if (IS_PTR(ltype->next) && left->isaddr) + { left = geniCodeRValue(left,FALSE); + } return geniCodeDerefPtr(geniCodeAdd(left,right)); } /* array access */ + if (/* getSize(ltype) > 1 && */(getSize(operandType(right)) < INTSIZE)) + { + /* Widen the index type to int first. */ + right = geniCodeCast(INTTYPE,right,TRUE); + } right = geniCodeMultiply(right, operandFromLit(getSize(ltype->next)));