X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=ecbe659b3b1d703ad5305ef7e390259a1cfb56a0;hb=aa10ccd6feb021eee2bc274ca1cbc938aeae6428;hp=9e25e4367f0b7d68ed3bdc09f7e137faa595340f;hpb=0299234dcc9718e0017d8a1a2d04c6b64220af2c;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 9e25e436..ecbe659b 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -24,6 +24,7 @@ #include "common.h" #include "newalloc.h" +#include "math.h" /*-----------------------------------------------------------------*/ /* global variables */ @@ -41,12 +42,6 @@ int scopeLevel; symbol *returnLabel; /* function return label */ symbol *entryLabel; /* function entry label */ -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define LONG_LONG __int64 -#else -#define LONG_LONG long long -#endif - /*-----------------------------------------------------------------*/ /* forward definition of some functions */ operand *geniCodeDivision (operand *, operand *); @@ -132,11 +127,28 @@ iCodeTable codeTable[] = */ void checkConstantRange(sym_link *ltype, value *val, char *msg, int pedantic) { - LONG_LONG max = (LONG_LONG) 1 << bitsForType(ltype); + double max; char message[132]=""; int warnings=0; int negative=0; - long v=SPEC_CVAL(val->type).v_long; + long v; + + max = pow ((double)2.0, (double)bitsForType(ltype)); + + if (SPEC_LONG(val->type)) { + if (SPEC_USIGN(val->type)) { + v=SPEC_CVAL(val->type).v_ulong; + } else { + v=SPEC_CVAL(val->type).v_long; + } + } else { + if (SPEC_USIGN(val->type)) { + v=SPEC_CVAL(val->type).v_uint; + } else { + v=SPEC_CVAL(val->type).v_int; + } + } + #if 0 // this could be a good idea @@ -1005,28 +1017,16 @@ operandOperation (operand * left, operand * right, operandLitValue (right)); break; case BITWISEAND: - retval = operandFromLit ((SPEC_USIGN(let) ? - (unsigned long) operandLitValue (left) : - (long) operandLitValue (left)) & - (SPEC_USIGN(ret) ? - (unsigned long) operandLitValue (right) : - (long) operandLitValue (right))); + retval = operandFromLit ((long)operandLitValue(left) & + (long)operandLitValue(right)); break; case '|': - retval = operandFromLit ((SPEC_USIGN(let) ? - (unsigned long) operandLitValue (left) : - (long) operandLitValue (left)) | - (SPEC_USIGN(ret) ? - (unsigned long) operandLitValue (right) : - (long) operandLitValue (right))); + retval = operandFromLit ((long)operandLitValue (left) | + (long)operandLitValue (right)); break; case '^': - retval = operandFromLit ((SPEC_USIGN(let) ? - (unsigned long) operandLitValue (left) : - (long) operandLitValue (left)) ^ - (SPEC_USIGN(ret) ? - (unsigned long) operandLitValue (right) : - (long) operandLitValue (right))); + retval = operandFromLit ((long)operandLitValue (left) ^ + (long)operandLitValue (right)); break; case AND_OP: retval = operandFromLit (operandLitValue (left) && @@ -1611,7 +1611,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) /* if casting to/from pointers, do some checking */ if (IS_PTR(type)) { // to a pointer - if (!IS_PTR(optype) && !IS_FUNC(optype)) { // from a non pointer + if (!IS_PTR(optype) && !IS_FUNC(optype) && !IS_AGGREGATE(optype)) { // from a non pointer if (IS_INTEGRAL(optype)) { // maybe this is NULL, than it's ok. if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) {