From 5176a0afa6144f13e53ef0731e8a631d966d1a3c Mon Sep 17 00:00:00 2001 From: johanknol Date: Mon, 1 Oct 2001 14:21:56 +0000 Subject: [PATCH] Too much opposition against these range checks. It will only work now with --pedantic (when it is implemented). git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1337 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCicode.c | 12 ++++++------ src/SDCCicode.h | 1 + src/SDCCval.c | 7 +++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 30bd5985..6d1b6b89 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -131,11 +131,12 @@ iCodeTable codeTable[] = pedantic>1: "char c=200" is not allowed (evaluates to -56) */ -void checkConstantRange(sym_link *ltype, double v, char *msg, int pedantic) { +void checkConstantRange(sym_link *ltype, value *val, char *msg, int pedantic) { LONG_LONG max = (LONG_LONG) 1 << bitsForType(ltype); char message[132]=""; int warnings=0; int negative=0; + long v=SPEC_CVAL(val->type).v_long; #if 0 // this could be a good idea @@ -148,10 +149,9 @@ void checkConstantRange(sym_link *ltype, double v, char *msg, int pedantic) { return; } - if (v<0) { + if (!SPEC_USIGN(val->type) && v<0) { negative=1; - // if not pedantic: -1 equals to 0xf..f - if (SPEC_USIGN(ltype) && (!pedantic ? v!=-1 : 1)) { + if (SPEC_USIGN(ltype) && (pedantic>1)) { warnings++; } v=-v; @@ -2507,7 +2507,7 @@ geniCodeLogic (operand * left, operand * right, int op) if (IS_INTEGRAL (ltype) && IS_VALOP (right) && IS_LITERAL (rtype)) { checkConstantRange(ltype, - operandLitValue(right), "compare operation", 1); + OP_VALUE(right), "compare operation", 1); } ctype = usualBinaryConversions (&left, &right); @@ -2600,7 +2600,7 @@ geniCodeAssign (operand * left, operand * right, int nosupdate) if (IS_INTEGRAL (ltype) && right->type == VALUE && IS_LITERAL (rtype)) { checkConstantRange(ltype, - operandLitValue(right), "= operation", 0); + OP_VALUE(right), "= operation", 0); } /* if the left & right type don't exactly match */ diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 5b6f3875..4156e257 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -68,6 +68,7 @@ OPTYPE; #define OP_SYMBOL(op) op->operand.symOperand #define OP_SYM_TYPE(op) op->operand.symOperand->type #define OP_SYM_ETYPE(op) op->operand.symOperand->etype +#define OP_VALUE(op) op->operand.valOperand #define SPIL_LOC(op) op->operand.symOperand->usl.spillLoc #define OP_LIVEFROM(op) op->operand.symOperand->liveFrom #define OP_LIVETO(op) op->operand.symOperand->liveTo diff --git a/src/SDCCval.c b/src/SDCCval.c index 7c16fbdb..845faf3f 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -373,8 +373,10 @@ constVal (char *s) SPEC_NOUN (val->type) = V_INT; SPEC_SCLS (val->type) = S_LITERAL; - /* set the _unsigned flag if 'uU' found */ - if (strchr (s, 'u') || strchr (s, 'U')) + /* set the _unsigned flag if 'uUoOxX' found */ + if (strchr (s, 'u') || strchr (s, 'U') || + strchr (s, 'o') || strchr (s, 'O') || + strchr (s, 'x') || strchr (s, 'x')) SPEC_USIGN (val->type) = 1; /* set the _long flag if 'lL' is found */ @@ -711,6 +713,7 @@ charVal (char *s) val->type = val->etype = newLink (); val->type->class = SPECIFIER; SPEC_NOUN (val->type) = V_CHAR; + SPEC_USIGN(val->type) = 1; SPEC_SCLS (val->type) = S_LITERAL; s++; /* get rid of quotation */ -- 2.30.2