X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCglue.c;h=54895c198e4679b5496e726511c577d631334a64;hb=654a8128d67d4f15d92fb94a86b11eb1db5cb8a6;hp=da74378f09a5e7171c73f0948c6a41c96106a4df;hpb=12a291f30d83a482bfa8c8e464f89eecbe57a4bf;p=fw%2Fsdcc diff --git a/src/SDCCglue.c b/src/SDCCglue.c index da74378f..54895c19 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -317,7 +317,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) /* initPointer - pointer initialization code massaging */ /*-----------------------------------------------------------------*/ value * -initPointer (initList * ilist) +initPointer (initList * ilist, sym_link *toType) { value *val; ast *expr = list2expr (ilist); @@ -329,6 +329,17 @@ initPointer (initList * ilist) if ((val = constExprValue (expr, FALSE))) return val; + /* (char *)&a */ + if (IS_AST_OP(expr) && expr->opval.op==CAST && + IS_AST_OP(expr->right) && expr->right->opval.op=='&') { + if (compareType(toType, expr->left->ftype)!=1) { + werror (W_INIT_WRONG); + printFromToType(expr->left->ftype, toType); + } + // skip the cast ??? + expr=expr->right; + } + /* no then we have to do these cludgy checks */ /* pointers can be initialized with address of a variable or address of an array element */ @@ -785,6 +796,11 @@ printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile) val = list2val (ilist); + if (!val) { + // an error has been thrown allready + val=constVal("0"); + } + if (IS_LITERAL(val->etype)) { if (compareType(type,val->etype)==0) { werror (E_INCOMPAT_TYPES); @@ -945,7 +961,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile) return; } - if (!(val = initPointer (ilist))) + if (!(val = initPointer (ilist, type))) return; /* if character pointer */ @@ -954,8 +970,10 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile) return; /* check the type */ - if (compareType (type, val->type) == 0) + if (compareType (type, val->type) == 0) { werror (W_INIT_WRONG); + printFromToType (val->type, from); + } /* if val is literal */ if (IS_LITERAL (val->etype)) @@ -1011,6 +1029,9 @@ printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile) if (!ilist) return; + /* update line number for error msgs */ + lineno=sym->lineDef; + /* if structure then */ if (IS_STRUCT (type)) { @@ -1464,10 +1485,12 @@ glue () /* create the overlay segments */ - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; overlayable items in internal ram \n"); - fprintf (asmFile, "%s", iComments2); - copyFile (asmFile, ovrFile); + if (overlay) { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; overlayable items in internal ram \n"); + fprintf (asmFile, "%s", iComments2); + copyFile (asmFile, ovrFile); + } /* create the stack segment MOF */ if (mainf && IFFUNC_HASBODY(mainf->type)) @@ -1480,10 +1503,12 @@ glue () } /* create the idata segment */ - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; indirectly addressable internal ram data\n"); - fprintf (asmFile, "%s", iComments2); - copyFile (asmFile, idata->oFile); + if (idata) { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; indirectly addressable internal ram data\n"); + fprintf (asmFile, "%s", iComments2); + copyFile (asmFile, idata->oFile); + } /* copy the bit segment */ fprintf (asmFile, "%s", iComments2);