fixed throw of "excess elements" warning for char arrays
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5231
4a8a32a2-be11-0410-ad9d-
d568d2c75423
+2008-09-07 Borut Razem <borut.razem AT siol.net>
+
+ * src/SDCCglue.c, src/SDCCast.c:
+ fixed throw of "excess elements" warning for char arrays
+
2008-06-04 Maarten Brock <sourceforge.brock AT dse.nl>
* as/z80/aslist.c (lstsym): changed old K&R to ANSI
2008-06-04 Maarten Brock <sourceforge.brock AT dse.nl>
* as/z80/aslist.c (lstsym): changed old K&R to ANSI
/* don't perform integer promotion of explicitly typecasted variable arguments
* if sdcc extensions are enabled */
/* don't perform integer promotion of explicitly typecasted variable arguments
* if sdcc extensions are enabled */
- if (options.std_sdcc &&
+ if (options.std_sdcc &&
(IS_CAST_OP (*actParm) ||
(IS_AST_SYM_VALUE (*actParm) && AST_VALUES (*actParm, removedCast)) ||
(IS_AST_LIT_VALUE (*actParm) && AST_VALUES (*actParm, literalFromCast))))
(IS_CAST_OP (*actParm) ||
(IS_AST_SYM_VALUE (*actParm) && AST_VALUES (*actParm, removedCast)) ||
(IS_AST_LIT_VALUE (*actParm) && AST_VALUES (*actParm, literalFromCast))))
if (!AST_SYMBOL (rootVal)->islocal || SPEC_STAT (getSpec (type)))
return NULL;
if (!AST_SYMBOL (rootVal)->islocal || SPEC_STAT (getSpec (type)))
return NULL;
- for (i=0; i<symsize; i++)
+ for (i = 0; i < symsize; ++i)
{
rast = newNode (NULLOP,
rast,
{
rast = newNode (NULLOP,
rast,
unsigned int symsize = getSize (type);
size = getSize (iexpr->ftype);
unsigned int symsize = getSize (type);
size = getSize (iexpr->ftype);
- if (symsize && size>symsize)
+ if (symsize && size > symsize)
{
char *name = (IS_AST_SYM_VALUE(sym)) ? AST_SYMBOL(sym)->name : "";
{
char *name = (IS_AST_SYM_VALUE(sym)) ? AST_SYMBOL(sym)->name : "";
+ for (i = 0; i < size; i++)
{
rast = newNode (NULLOP,
rast,
newNode ('=',
newNode ('[', sym,
newAst_VALUE (valueFromLit ((float) i))),
{
rast = newNode (NULLOP,
rast,
newNode ('=',
newNode ('[', sym,
newAst_VALUE (valueFromLit ((float) i))),
- newAst_VALUE (valueFromLit (*s))));
- s++;
+ newAst_VALUE (valueFromLit (*s++))));
}
// now WE don't need iexpr's symbol anymore
}
// now WE don't need iexpr's symbol anymore
symbol *interrupts[INTNO_MAX+1];
symbol *interrupts[INTNO_MAX+1];
-void printIval (symbol *, sym_link *, initList *, struct dbuf_s *);
+void printIval (symbol *, sym_link *, initList *, struct dbuf_s *, bool check);
set *publics = NULL; /* public variables */
set *externs = NULL; /* Variables that are declared as extern */
set *publics = NULL; /* public variables */
set *externs = NULL; /* Variables that are declared as extern */
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
++noInit;
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
++noInit;
- printIval (sym, sym->type, sym->ival, &tmpBuf);
+ printIval (sym, sym->type, sym->ival, &tmpBuf, TRUE);
--noInit;
--noAlloc;
dbuf_destroy(&tmpBuf);
--noInit;
--noAlloc;
dbuf_destroy(&tmpBuf);
}
if (SPEC_STRUCT (type)->type == UNION) {
}
if (SPEC_STRUCT (type)->type == UNION) {
- printIval (sym, sflds->type, iloop, oBuf);
+ printIval (sym, sflds->type, iloop, oBuf, TRUE);
iloop = iloop ? iloop->next : NULL;
} else {
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
if (IS_BITFIELD(sflds->type)) {
printIvalBitFields(&sflds, &iloop, oBuf);
} else {
iloop = iloop ? iloop->next : NULL;
} else {
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
if (IS_BITFIELD(sflds->type)) {
printIvalBitFields(&sflds, &iloop, oBuf);
} else {
- printIval (sym, sflds->type, iloop, oBuf);
+ printIval (sym, sflds->type, iloop, oBuf, TRUE);
/* printIvalChar - generates initital value for character array */
/*-----------------------------------------------------------------*/
int
/* printIvalChar - generates initital value for character array */
/*-----------------------------------------------------------------*/
int
-printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s)
+printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s, bool check)
{
value *val;
unsigned int size = DCL_ELEM (type);
{
value *val;
unsigned int size = DCL_ELEM (type);
DCL_ELEM (type) = size;
}
DCL_ELEM (type) = size;
}
+ if (check && DCL_ELEM (val->type) > size)
+ werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef);
+
printChar (oBuf, SPEC_CVAL (val->etype).v_char, size);
return 1;
printChar (oBuf, SPEC_CVAL (val->etype).v_char, size);
return 1;
/*-----------------------------------------------------------------*/
void
printIvalArray (symbol * sym, sym_link * type, initList * ilist,
/*-----------------------------------------------------------------*/
void
printIvalArray (symbol * sym, sym_link * type, initList * ilist,
+ struct dbuf_s * oBuf, bool check)
{
value *val;
initList *iloop;
{
value *val;
initList *iloop;
}
if (printIvalChar (sym, type,
(ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
}
if (printIvalChar (sym, type,
(ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
- oBuf, SPEC_CVAL (sym->etype).v_char))
+ oBuf, SPEC_CVAL (sym->etype).v_char, check))
return;
}
/* not the special case */
return;
}
/* not the special case */
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
break;
}
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
break;
}
- printIval (sym, type->next, iloop, oBuf);
+ printIval (sym, type->next, iloop, oBuf, TRUE);
/* printIval - generates code for initial value */
/*-----------------------------------------------------------------*/
void
/* printIval - generates code for initial value */
/*-----------------------------------------------------------------*/
void
-printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf)
+printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, bool check)
/* if this is an array */
if (IS_ARRAY (type))
{
/* if this is an array */
if (IS_ARRAY (type))
{
- printIvalArray (sym, type, ilist, oBuf);
+ printIvalArray (sym, type, ilist, oBuf, check);
dbuf_printf (oBuf, "%s:\n", sym->rname);
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
dbuf_printf (oBuf, "%s:\n", sym->rname);
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
- printIval (sym, sym->type, sym->ival, oBuf);
+ printIval (sym, sym->type, sym->ival, oBuf, map != xinit);
--noAlloc;
/* if sym is a simple string and sym->ival is a string,
WE don't need it anymore */
--noAlloc;
/* if sym is a simple string and sym->ival is a string,
WE don't need it anymore */