From 89ced3c908df7524953073632212e98f40566081 Mon Sep 17 00:00:00 2001 From: epetrich Date: Fri, 12 Sep 2003 07:56:35 +0000 Subject: [PATCH] Fixed bug #621531 (const & volatile confusion in the type chain). DCL_PTR_CONST, DCL_PTR_VOLATILE, & IS_PTR_CONST now exclusively refer to the const or volatile state of the pointer itself. * src/SDCCast.c * src/SDCCglue.c * src/SDCCicode.c * src/SDCCsymt.c * src/SDCCval.c * src/SDCC.y * src/SDCCsymt.h * src/pic/gen.c * src/pic/ralloc.c * src/pic16/gen.c * src/pic16/ralloc.c * support/regression/tests/const.c git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2885 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 19 +++ src/SDCC.y | 3 +- src/SDCCast.c | 19 +-- src/SDCCglue.c | 5 +- src/SDCCicode.c | 44 +----- src/SDCCsymt.c | 230 ++++++++++++++++++++++++++++--- src/SDCCsymt.h | 1 + src/SDCCval.c | 10 +- src/pic/gen.c | 26 ++++ src/pic/ralloc.c | 8 ++ src/pic16/gen.c | 30 ++++ src/pic16/ralloc.c | 8 ++ support/regression/tests/const.c | 52 +++++++ 13 files changed, 374 insertions(+), 81 deletions(-) create mode 100644 support/regression/tests/const.c diff --git a/ChangeLog b/ChangeLog index 04801903..816ae1d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-09-12 Erik Petrich + + Fixed bug #621531 (const & volatile confusion in the type chain). + DCL_PTR_CONST, DCL_PTR_VOLATILE, & IS_PTR_CONST now exclusively + refer to the const or volatile state of the pointer itself. + + * src/SDCCast.c + * src/SDCCglue.c + * src/SDCCicode.c + * src/SDCCsymt.c + * src/SDCCval.c + * src/SDCC.y + * src/SDCCsymt.h + * src/pic/gen.c + * src/pic/ralloc.c + * src/pic16/gen.c + * src/pic16/ralloc.c + * support/regression/tests/const.c + 2003-09-10 Jesus Calvino-Fraga When checking for duplicated modules, use absolute paths diff --git a/src/SDCC.y b/src/SDCC.y index 9b6492e9..67b89862 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -1027,6 +1027,8 @@ pointer { $$ = $1 ; DCL_TSPEC($1) = $2; + DCL_PTR_CONST($1) = SPEC_CONST($2); + DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2); } | unqualified_pointer pointer { @@ -1054,7 +1056,6 @@ pointer DCL_TYPE($3) = POINTER ; break; case S_CODE: - DCL_PTR_CONST($3) = 1; DCL_TYPE($3) = CPOINTER ; break; case S_EEPROM: diff --git a/src/SDCCast.c b/src/SDCCast.c index b230e23c..c531c898 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2056,9 +2056,6 @@ decorateType (ast * tree) } RRVAL (tree) = 1; COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next); - if (IS_PTR(LTYPE(tree))) { - SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree)); - } return tree; /*------------------------------------------------------------------*/ @@ -2134,12 +2131,12 @@ decorateType (ast * tree) /*----------------------------*/ /* ++/-- operation */ /*----------------------------*/ - case INC_OP: /* incerement operator unary so left only */ + case INC_OP: /* increment operator unary so left only */ case DEC_OP: { sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree)); COPYTYPE (TTYPE (tree), TETYPE (tree), ltc); - if (!tree->initMode && IS_CONSTANT(TETYPE(tree))) + if (!tree->initMode && IS_CONSTANT(TTYPE(tree))) werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--"); if (tree->right) @@ -2235,10 +2232,7 @@ decorateType (ast * tree) goto errorTreeReturn; } if (SPEC_SCLS (tree->left->etype) == S_CODE) - { - DCL_TYPE (p) = CPOINTER; - DCL_PTR_CONST (p) = port->mem.code_ro; - } + DCL_TYPE (p) = CPOINTER; else if (SPEC_SCLS (tree->left->etype) == S_XDATA) DCL_TYPE (p) = FPOINTER; else if (SPEC_SCLS (tree->left->etype) == S_XSTACK) @@ -2261,8 +2255,6 @@ decorateType (ast * tree) p->next = LTYPE (tree); TTYPE (tree) = p; TETYPE (tree) = getSpec (TTYPE (tree)); - DCL_PTR_CONST (p) = SPEC_CONST (TETYPE (tree)); - DCL_PTR_VOLATILE (p) = SPEC_VOLATILE (TETYPE (tree)); LLVAL (tree) = 1; TLVAL (tree) = 1; return tree; @@ -2393,8 +2385,7 @@ decorateType (ast * tree) goto errorTreeReturn; } TTYPE (tree) = copyLinkChain (LTYPE (tree)->next); - TETYPE (tree) = getSpec (TTYPE (tree)); - SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree)); + TETYPE (tree) = getSpec (TTYPE (tree)); return tree; } @@ -3245,7 +3236,7 @@ decorateType (ast * tree) RRVAL (tree) = 1; LLVAL (tree) = 1; if (!tree->initMode ) { - if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree)))) + if (IS_CONSTANT(LTYPE(tree))) werror (E_CODE_WRITE, "="); } if (LRVAL (tree)) diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 6e7a5a39..5a12ac3b 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -289,7 +289,10 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) SPEC_OCLS(newSym->etype)=xinit; SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name); SNPRINTF (newSym->rname, sizeof(newSym->rname), "__xinit_%s", sym->rname); - SPEC_CONST(newSym->etype)=1; + if (IS_SPEC (newSym->type)) + SPEC_CONST (newSym->type) = 1; + else + DCL_PTR_CONST (newSym->type) = 1; SPEC_STAT(newSym->etype)=1; resolveIvalSym(newSym->ival); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index d62a96fe..44dddc11 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2198,19 +2198,8 @@ aggrToPtr (sym_link * type, bool force) ptype->next = type; - /* if the output class is code */ - if ((DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype))) == CPOINTER) - DCL_PTR_CONST (ptype) = port->mem.code_ro; - - /* if the variable was declared a constant */ - /* then the pointer points to a constant */ - if (IS_CONSTANT (etype)) - DCL_PTR_CONST (ptype) = 1; - - /* the variable was volatile then pointer to volatile */ - if (IS_VOLATILE (etype)) - DCL_PTR_VOLATILE (ptype) = 1; - + /* set the pointer depending on the storage class */ + DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype)); return ptype; } @@ -2224,17 +2213,7 @@ geniCodeArray2Ptr (operand * op) sym_link *opetype = getSpec (optype); /* set the pointer depending on the storage class */ - if ((DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER) - DCL_PTR_CONST (optype) = port->mem.code_ro; - - /* if the variable was declared a constant */ - /* then the pointer points to a constant */ - if (IS_CONSTANT (opetype)) - DCL_PTR_CONST (optype) = 1; - - /* the variable was volatile then pointer to volatile */ - if (IS_VOLATILE (opetype)) - DCL_PTR_VOLATILE (optype) = 1; + DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype)); op->isaddr = 0; return op; @@ -2309,7 +2288,7 @@ geniCodeStruct (operand * left, operand * right, bool islval) retype = getSpec (operandType (IC_RESULT (ic))); SPEC_SCLS (retype) = SPEC_SCLS (etype); SPEC_OCLS (retype) = SPEC_OCLS (etype); - SPEC_VOLATILE (retype) |= SPEC_VOLATILE (etype); + SPEC_VOLATILE (retype) |= SPEC_VOLATILE (etype); /* EEP - I'm doubtful about this */ if (IS_PTR (element->type)) setOperandType (IC_RESULT (ic), aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); @@ -2522,15 +2501,7 @@ geniCodeAddressOf (operand * op) p = newLink (DECLARATOR); /* set the pointer depending on the storage class */ - if ((DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER) - DCL_PTR_CONST (p) = port->mem.code_ro; - - /* make sure we preserve the const & volatile */ - if (IS_CONSTANT (opetype)) - DCL_PTR_CONST (p) = 1; - - if (IS_VOLATILE (opetype)) - DCL_PTR_VOLATILE (p) = 1; + DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype)); p->next = copyLinkChain (optype); @@ -2630,11 +2601,6 @@ geniCodeDerefPtr (operand * op,int lvl) op->isGptr = IS_GENPTR (optype); - /* if the pointer was declared as a constant */ - /* then we cannot allow assignment to the derefed */ - if (IS_PTR_CONST (optype)) - SPEC_CONST (retype) = 1; - op->isaddr = (IS_PTR (rtype) || IS_STRUCT (rtype) || IS_INT (rtype) || diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 21341726..e563fa28 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -25,6 +25,7 @@ #include "newalloc.h" value *aggregateToPointer (value *val); +void printTypeChainRaw (sym_link * start, FILE * of); void printFromToType(sym_link *from, sym_link *to) { fprintf (stderr, "from type '"); @@ -349,8 +350,6 @@ pointerTypes (sym_link * ptr, sym_link * type) storage class of the type */ if (IS_SPEC (type)) { - DCL_PTR_CONST (ptr) = SPEC_CONST (type); - DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type); switch (SPEC_SCLS (type)) { case S_XDATA: @@ -366,7 +365,6 @@ pointerTypes (sym_link * ptr, sym_link * type) DCL_TYPE (ptr) = POINTER; break; case S_CODE: - DCL_PTR_CONST (ptr) = port->mem.code_ro; DCL_TYPE (ptr) = CPOINTER; break; case S_EEPROM: @@ -377,9 +375,7 @@ pointerTypes (sym_link * ptr, sym_link * type) break; } /* the storage class of type ends here */ - SPEC_SCLS (type) = - SPEC_CONST (type) = - SPEC_VOLATILE (type) = 0; + SPEC_SCLS (type) = 0; } /* now change all the remaining unknown pointers @@ -399,7 +395,6 @@ pointerTypes (sym_link * ptr, sym_link * type) DCL_TYPE (type) = port->unqualified_pointer; type = type->next; } - } /*------------------------------------------------------------------*/ @@ -472,8 +467,6 @@ addDecl (symbol * sym, int type, sym_link * p) sym->etype = sym->etype->next = newLink (SPECIFIER); } SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p)); - SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p)); - SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p)); DCL_TSPEC (p) = NULL; } @@ -1161,11 +1154,13 @@ compStructSize (int su, structdef * sdef) static void checkSClass (symbol * sym, int isProto) { + sym_link *t; + if (getenv("DEBUG_SANITY")) { fprintf (stderr, "checkSClass: %s \n", sym->name); } - /* type is literal can happen foe enums change + /* type is literal can happen for enums change to auto */ if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype)) SPEC_SCLS (sym->etype) = S_AUTO; @@ -1188,24 +1183,46 @@ checkSClass (symbol * sym, int isProto) if (IS_ABSOLUTE (sym->etype)) SPEC_VOLATILE (sym->etype) = 1; + /* If code memory is read only, then pointers to code memory */ + /* implicitly point to constants -- make this explicit */ + t = sym->type; + while (t && t->next) { + if (IS_CODEPTR(t) && port->mem.code_ro) { + if (IS_SPEC(t->next)) { + SPEC_CONST (t->next) = 1; + } else { + DCL_PTR_CONST (t->next) = 1; + } + } + t = t->next; + } /* global variables declared const put into code */ /* if no other storage class specified */ if (sym->level == 0 && - SPEC_CONST (sym->etype) && SPEC_SCLS(sym->etype) == S_FIXED && !IS_FUNC(sym->type)) { - SPEC_SCLS (sym->etype) = S_CODE; + /* find the first non-array link */ + t = sym->type; + while (IS_ARRAY(t)) + t = t->next; + if (IS_CONSTANT (t)) { + SPEC_SCLS (sym->etype) = S_CODE; + } } /* global variable in code space is a constant */ if (sym->level == 0 && SPEC_SCLS (sym->etype) == S_CODE && port->mem.code_ro) { - if (IS_SPEC(sym->type)) { - SPEC_CONST (sym->type) = 1; + /* find the first non-array link */ + t = sym->type; + while (IS_ARRAY(t)) + t = t->next; + if (IS_SPEC(t)) { + SPEC_CONST (t) = 1; } else { - DCL_PTR_CONST (sym->type) = 1; + DCL_PTR_CONST (t) = 1; } } @@ -1228,7 +1245,7 @@ checkSClass (symbol * sym, int isProto) sym->ival = NULL; } - /* if this is an atomatic symbol */ + /* if this is an automatic symbol */ if (sym->level && (options.stackAuto || reentrant)) { if ((SPEC_SCLS (sym->etype) == S_AUTO || SPEC_SCLS (sym->etype) == S_FIXED || @@ -1451,6 +1468,10 @@ computeType (sym_link * type1, sym_link * type2) rType = copyLinkChain (type2); reType = getSpec (rType); +#if 0 + if (SPEC_NOUN (reType) == V_CHAR) + SPEC_NOUN (reType) = V_INT; +#endif /* if either of them unsigned but not val then make this unsigned */ if (((/*!IS_LITERAL(type1) &&*/ SPEC_USIGN (etype1)) || @@ -2011,7 +2032,10 @@ printTypeChain (sym_link * start, FILE * of) for (type = start; type && type->next; type = type->next) ; - scls=SPEC_SCLS(type); + if (IS_SPEC (type)) + scls=SPEC_SCLS(type); + else + scls=0; while (type) { if (type==start) { @@ -2081,7 +2105,7 @@ printTypeChain (sym_link * start, FILE * of) fprintf (of, "pdata* "); break; case UPOINTER: - fprintf (of, "unkown* "); + fprintf (of, "unknown* "); break; case ARRAY: if (DCL_ELEM(type)) { @@ -2156,6 +2180,176 @@ printTypeChain (sym_link * start, FILE * of) fprintf (of, "\n"); } +/*--------------------------------------------------------------------*/ +/* printTypeChainRaw - prints the type chain in human readable form */ +/* in the raw data structure ordering */ +/*--------------------------------------------------------------------*/ +void +printTypeChainRaw (sym_link * start, FILE * of) +{ + int nlr = 0; + value *args; + sym_link * type; + + if (!of) + { + of = stdout; + nlr = 1; + } + + if (start==NULL) { + fprintf (of, "void"); + return; + } + + type = start; + + while (type) + { + if (IS_DECL (type)) + { + if (!IS_FUNC(type)) { + if (DCL_PTR_VOLATILE (type)) { + fprintf (of, "volatile-"); + } + if (DCL_PTR_CONST (type)) { + fprintf (of, "const-"); + } + } + switch (DCL_TYPE (type)) + { + case FUNCTION: + fprintf (of, "function %s %s", + (IFFUNC_ISBUILTIN(type) ? "__builtin__" : " "), + (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " ")); + fprintf (of, "( "); + for (args = FUNC_ARGS(type); + args; + args=args->next) { + printTypeChain(args->type, of); + if (args->next) + fprintf(of, ", "); + } + fprintf (of, ") "); + break; + case GPOINTER: + fprintf (of, "generic* "); + break; + case CPOINTER: + fprintf (of, "code* "); + break; + case FPOINTER: + fprintf (of, "xdata* "); + break; + case EEPPOINTER: + fprintf (of, "eeprom* "); + break; + case POINTER: + fprintf (of, "near* "); + break; + case IPOINTER: + fprintf (of, "idata* "); + break; + case PPOINTER: + fprintf (of, "pdata* "); + break; + case UPOINTER: + fprintf (of, "unknown* "); + break; + case ARRAY: + if (DCL_ELEM(type)) { + fprintf (of, "[%d] ", DCL_ELEM(type)); + } else { + fprintf (of, "[] "); + } + break; + } + if (DCL_TSPEC(type)) + { + fprintf (of, "{"); + printTypeChainRaw(DCL_TSPEC(type), of); + fprintf (of, "}"); + } + } + else if (IS_SPEC (type)) + { + switch (SPEC_SCLS (type)) + { + case S_DATA: fprintf (of, "data-"); break; + case S_XDATA: fprintf (of, "xdata-"); break; + case S_SFR: fprintf (of, "sfr-"); break; + case S_SBIT: fprintf (of, "sbit-"); break; + case S_CODE: fprintf (of, "code-"); break; + case S_IDATA: fprintf (of, "idata-"); break; + case S_PDATA: fprintf (of, "pdata-"); break; + case S_LITERAL: fprintf (of, "literal-"); break; + case S_STACK: fprintf (of, "stack-"); break; + case S_XSTACK: fprintf (of, "xstack-"); break; + case S_BIT: fprintf (of, "bit-"); break; + case S_EEPROM: fprintf (of, "eeprom-"); break; + default: break; + } + if (SPEC_VOLATILE (type)) + fprintf (of, "volatile-"); + if (SPEC_CONST (type)) + fprintf (of, "const-"); + if (SPEC_USIGN (type)) + fprintf (of, "unsigned-"); + switch (SPEC_NOUN (type)) + { + case V_INT: + if (IS_LONG (type)) + fprintf (of, "long-"); + fprintf (of, "int"); + break; + + case V_CHAR: + fprintf (of, "char"); + break; + + case V_VOID: + fprintf (of, "void"); + break; + + case V_FLOAT: + fprintf (of, "float"); + break; + + case V_STRUCT: + fprintf (of, "struct %s", SPEC_STRUCT (type)->tag); + break; + + case V_SBIT: + fprintf (of, "sbit"); + break; + + case V_BIT: + fprintf (of, "bit"); + break; + + case V_BITFIELD: + fprintf (of, "bitfield {%d,%d}", SPEC_BSTR (type), SPEC_BLEN (type)); + break; + + case V_DOUBLE: + fprintf (of, "double"); + break; + + default: + fprintf (of, "unknown type"); + break; + } + } + else + fprintf (of, "NOT_SPEC_OR_DECL"); + type = type->next; + if (type) + fputc (' ', of); + } + if (nlr) + fprintf (of, "\n"); +} + /*-----------------------------------------------------------------*/ /* powof2 - returns power of two for the number if number is pow 2 */ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index c41303ed..5690d649 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -541,6 +541,7 @@ void processFuncArgs (symbol *); int isSymbolEqual (symbol *, symbol *); int powof2 (unsigned long); void printTypeChain (sym_link *, FILE *); +void printTypeChainRaw (sym_link *, FILE *); void initCSupport (); void initBuiltIns (); void pointerTypes (sym_link *, sym_link *); diff --git a/src/SDCCval.c b/src/SDCCval.c index 30b9446e..b1f5e390 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1603,10 +1603,7 @@ valForArray (ast * arrExpr) val->type = newLink (DECLARATOR); if (SPEC_SCLS (arrExpr->left->etype) == S_CODE) - { - DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; - } + DCL_TYPE (val->type) = CPOINTER; else if (SPEC_SCLS (arrExpr->left->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; else if (SPEC_SCLS (arrExpr->left->etype) == S_XSTACK) @@ -1674,10 +1671,7 @@ valForStructElem (ast * structT, ast * elemT) val->type = newLink (DECLARATOR); if (SPEC_SCLS (structT->etype) == S_CODE) - { - DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; - } + DCL_TYPE (val->type) = CPOINTER; else if (SPEC_SCLS (structT->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; else if (SPEC_SCLS (structT->etype) == S_XSTACK) diff --git a/src/pic/gen.c b/src/pic/gen.c index c2bb459f..f8b48f8d 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -610,7 +610,11 @@ static asmop *aopForRemat (operand *op) // x symbol *sym) offset = OP_SYMBOL(IC_LEFT(ic))->offset; aop->aopu.pcop = popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val,0); +#if 0 PCOI(aop->aopu.pcop)->_const = IS_PTR_CONST(operandType(op)); +#else + PCOI(aop->aopu.pcop)->_const = IS_CODEPTR(operandType(op)); +#endif PCOI(aop->aopu.pcop)->index = val; DEBUGpic14_emitcode(";","%d: rname %s, val %d, const = %d", @@ -763,7 +767,11 @@ void aopOp (operand *op, iCode *ic, bool result) { sym_link *type = operandType(op); +#if 0 if(IS_PTR_CONST(type)) +#else + if(IS_CODEPTR(type)) +#endif DEBUGpic14_emitcode(";","%d aop type is const pointer",__LINE__); } @@ -882,7 +890,11 @@ void aopOp (operand *op, iCode *ic, bool result) { sym_link *type = operandType(op); +#if 0 if(IS_PTR_CONST(type)) +#else + if(IS_CODEPTR(type)) +#endif DEBUGpic14_emitcode(";","%d aop type is const pointer",__LINE__); } @@ -8393,7 +8405,11 @@ static void genPointerGet (iCode *ic) type = operandType(left); etype = getSpec(type); +#if 0 if (IS_PTR_CONST(type)) +#else + if (IS_CODEPTR(type)) +#endif DEBUGpic14_emitcode ("; ***","%d - const pointer",__LINE__); /* if left is of type of pointer then it is simple */ @@ -8449,9 +8465,11 @@ static void genPointerGet (iCode *ic) break; case GPOINTER: +#if 0 if (IS_PTR_CONST(type)) genConstPointerGet (left,result,ic); else +#endif genGenPointerGet (left,result,ic); break; } @@ -9609,9 +9627,17 @@ static void genCast (iCode *ic) goto release; DEBUGpic14_emitcode("; ***","%s %d",__FUNCTION__,__LINE__); +#if 0 if (IS_PTR_CONST(rtype)) +#else + if (IS_CODEPTR(rtype)) +#endif DEBUGpic14_emitcode ("; ***","%d - right is const pointer",__LINE__); +#if 0 if (IS_PTR_CONST(operandType(IC_RESULT(ic)))) +#else + if (IS_CODEPTR(operandType(IC_RESULT(ic)))) +#endif DEBUGpic14_emitcode ("; ***","%d - result is const pointer",__LINE__); if ((AOP_TYPE(right) == AOP_PCODE) && AOP(right)->aopu.pcop->type == PO_IMMEDIATE) { diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 5c8e6dd1..6f6ea8e8 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -2504,7 +2504,11 @@ regTypeNum () getSize (sym->type)); +#if 0 if(IS_PTR_CONST (sym->type)) { +#else + if(IS_CODEPTR (sym->type)) { +#endif debugLog (" %d const pointer type requires %d registers, changing to 2\n",__LINE__,sym->nRegs); sym->nRegs = 2; } @@ -3501,7 +3505,11 @@ packRegisters (eBBlock * ebp) sym_link *etype = getSpec (operandType (IC_LEFT (ic))); debugAopGet (" left:", IC_LEFT (ic)); +#if 0 if(IS_PTR_CONST(OP_SYMBOL(IC_LEFT(ic))->type)) +#else + if(IS_CODEPTR(OP_SYMBOL(IC_LEFT(ic))->type)) +#endif debugLog (" is a pointer\n"); if(IS_OP_VOLATILE(IC_LEFT(ic))) diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 0245249b..367ae284 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -612,12 +612,20 @@ static asmop *aopForRemat (operand *op) // x symbol *sym) offset = OP_SYMBOL(IC_LEFT(ic))->offset; aop->aopu.pcop = pic16_popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val); +#if 0 PCOI(aop->aopu.pcop)->_const = IS_PTR_CONST(operandType(op)); +#else + PCOI(aop->aopu.pcop)->_const = IS_CODEPTR(operandType(op)); +#endif PCOI(aop->aopu.pcop)->index = val; DEBUGpic16_emitcode(";","%d: rname %s, val %d, const = %d", __LINE__,OP_SYMBOL(IC_LEFT(ic))->rname, +#if 0 val, IS_PTR_CONST(operandType(op))); +#else + val, IS_CODEPTR(operandType(op))); +#endif // DEBUGpic16_emitcode(";","aop type %s",pic16_AopType(AOP_TYPE(IC_LEFT(ic)))); @@ -765,7 +773,11 @@ void pic16_aopOp (operand *op, iCode *ic, bool result) { sym_link *type = operandType(op); +#if 0 if(IS_PTR_CONST(type)) +#else + if(IS_CODEPTR(type)) +#endif DEBUGpic16_emitcode(";","%d aop type is const pointer",__LINE__); } @@ -872,7 +884,11 @@ void pic16_aopOp (operand *op, iCode *ic, bool result) { sym_link *type = operandType(op); +#if 0 if(IS_PTR_CONST(type)) +#else + if(IS_CODEPTR(type)) +#endif DEBUGpic16_emitcode(";","%d aop type is const pointer",__LINE__); } @@ -8402,7 +8418,11 @@ static void genPointerGet (iCode *ic) type = operandType(left); etype = getSpec(type); +#if 0 if (IS_PTR_CONST(type)) +#else + if (IS_CODEPTR(type)) +#endif DEBUGpic16_emitcode ("; ***","%d - const pointer",__LINE__); /* if left is of type of pointer then it is simple */ @@ -8458,9 +8478,11 @@ static void genPointerGet (iCode *ic) break; case GPOINTER: +#if 0 if (IS_PTR_CONST(type)) genConstPointerGet (left,result,ic); else +#endif genGenPointerGet (left,result,ic); break; } @@ -9637,9 +9659,17 @@ static void genCast (iCode *ic) goto release; DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__); +#if 0 if (IS_PTR_CONST(rtype)) +#else + if (IS_CODEPTR(rtype)) +#endif DEBUGpic16_emitcode ("; ***","%d - right is const pointer",__LINE__); +#if 0 if (IS_PTR_CONST(operandType(IC_RESULT(ic)))) +#else + if (IS_CODEPTR(operandType(IC_RESULT(ic)))) +#endif DEBUGpic16_emitcode ("; ***","%d - result is const pointer",__LINE__); if ((AOP_TYPE(right) == AOP_PCODE) && AOP(right)->aopu.pcop->type == PO_IMMEDIATE) { diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 03849b7d..e5cfcb35 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -2501,7 +2501,11 @@ regTypeNum () getSize (sym->type)); +#if 0 if(IS_PTR_CONST (sym->type)) { +#else + if(IS_CODEPTR (sym->type)) { +#endif debugLog (" %d const pointer type requires %d registers, changing to 2\n",__LINE__,sym->nRegs); sym->nRegs = 2; } @@ -3495,7 +3499,11 @@ packRegisters (eBBlock * ebp) sym_link *etype = getSpec (operandType (IC_LEFT (ic))); debugAopGet (" left:", IC_LEFT (ic)); +#if 0 if(IS_PTR_CONST(OP_SYMBOL(IC_LEFT(ic))->type)) +#else + if(IS_CODEPTR(OP_SYMBOL(IC_LEFT(ic))->type)) +#endif debugLog (" is a pointer\n"); if(IS_OP_VOLATILE(IC_LEFT(ic))) diff --git a/support/regression/tests/const.c b/support/regression/tests/const.c new file mode 100644 index 00000000..90470f10 --- /dev/null +++ b/support/regression/tests/const.c @@ -0,0 +1,52 @@ +/* Tests usage of const qualifier. + */ +#include + +char k; /* char */ +const char const_char = 123; /* constant char */ +const char * const_char_ptr; /* pointer to constant char */ +char * const char_ptr_const = &k; /* constant pointer to char */ +const char * const const_char_ptr_const = &const_char; + /* constant pointer to constant char */ +char char_array[3]; /* array of char */ +const char const_char_array[] = {1,2,3}; /* array of constant char */ +const char ** const_char_ptr_ptr; /* pointer to pointer to constant char */ + +char +ident(char x) +{ + return x; +} + +void +testConst(void) +{ + /* Since const_char_ptr is in itself not constant, we can change it */ + const_char_ptr = const_char_array; + const_char_ptr++; + ASSERT(*const_char_ptr == 2); + + /* Check for bug #621531 */ + const_char_ptr = const_char_array; + ASSERT(const_char_ptr[0] == 1); + const_char_ptr++; + + /* Since char_ptr_const is constant, we cannot change it. However, */ + /* we can change the object that it points to. */ + *char_ptr_const = 5; + ASSERT(ident(*char_ptr_const)==5); + (*char_ptr_const)++; + ASSERT(ident(*char_ptr_const)==6); + + /* We can't modify const_char_ptr_const or the object that it points */ + /* to. Unfortunately, we can't test that compiler enforces these */ + /* restriction, so just verify its initialization. */ + ASSERT(*const_char_ptr_const == const_char); + + /* We can change const_char_ptr_ptr or the object that it points to. */ + const_char_ptr = const_char_array; + const_char_ptr_ptr = &const_char_ptr; + ASSERT(ident(**const_char_ptr_ptr)==1); + (*const_char_ptr_ptr)++; + ASSERT(ident(**const_char_ptr_ptr)==2); +} -- 2.47.2