if (name)
{
unlink (name);
- free (name);
+ Safe_free (name);
}
return 0;
}
}
fl;
+ if (!val) {
+ // assuming we have been warned before
+ val=constVal("0");
+ }
+
/* if it is a float then it gets tricky */
/* otherwise it is fairly simple */
if (!IS_FLOAT (val->type)) {
/* if allocation required check is needed
then check if the symbol really requires
allocation only for local variables */
+
if (arFlag && !IS_AGGREGATE (sym->type) &&
!(sym->_isparm && !IS_REGPARM (sym->etype)) &&
!sym->allocreq && sym->level)
continue;
+ /* for bitvar locals and parameters */
+ if (!arFlag && !sym->allocreq && sym->level
+ && !SPEC_ABSA (sym->etype)) {
+ continue;
+ }
+
/* if global variable & not static or extern
and addPublics allowed then add it to the public set */
if ((sym->level == 0 ||
(sym->_isparm && !IS_REGPARM (sym->etype))) &&
addPublics &&
!IS_STATIC (sym->etype) &&
- (IS_FUNC(sym->type) ? (sym->used || sym->fbody) : 1))
+ (IS_FUNC(sym->type) ? (sym->used || IFFUNC_HASBODY(sym->type)) : 1))
{
addSetHead (&publics, sym);
}
it is a global variable */
if (sym->ival && sym->level == 0)
{
- if (IS_AGGREGATE (sym->type))
+ if (IS_AGGREGATE (sym->type)) {
ival = initAggregates (sym, sym->ival, NULL);
- else
+ } else {
+ if (getNelements(sym->type, sym->ival)>1) {
+ werror (W_EXCESS_INITIALIZERS, "scalar",
+ sym->name, sym->lineDef);
+ }
ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
decorateType (resolveSymbols (list2expr (sym->ival))));
+ }
codeOutFile = statsg->oFile;
allocInfo = 0;
// set ival's lineno to where the symbol was defined
- ival->lineno=sym->lineDef;
-
+ if (ival) ival->lineno=sym->lineDef;
eBBlockFromiCode (iCodeFromAst (ival));
allocInfo = 1;
- /* if the ival was a symbol, delete it from its segment */
- if (IS_AST_SYM_VALUE(sym->ival->init.node)) {
+ /* if the ival is a symbol assigned to an aggregate,
+ (bug #458099 -> #462479)
+ we don't need it anymore, so delete it from its segment */
+ if (sym->ival->type == INIT_NODE &&
+ IS_AST_SYM_VALUE(sym->ival->init.node) &&
+ IS_AGGREGATE (sym->type) ) {
symIval=AST_SYMBOL(sym->ival->init.node);
segment = SPEC_OCLS (symIval->etype);
deleteSetItem (&segment->syms, symIval);
}
+
sym->ival = NULL;
}
}
return val;
}
wrong:
- werror (E_INIT_WRONG);
+ werror (W_INIT_WRONG);
return NULL;
}
/* printIvalType - generates ival for int/char */
/*-----------------------------------------------------------------*/
void
-printIvalType (sym_link * type, initList * ilist, FILE * oFile)
+printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile)
{
value *val;
if (ilist->type == INIT_DEEP)
ilist = ilist->init.deep;
+ if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
+ werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef);
+ }
+
val = list2val (ilist);
switch (getSize (type)) {
case 1:
if (IS_BITFIELD(sflds->type)) {
printIvalBitFields(&sflds,&iloop,oFile);
} else {
- printIval (sflds, sflds->type, iloop, oFile);
+ printIval (sym, sflds->type, iloop, oFile);
}
}
+ if (iloop) {
+ werror (W_EXCESS_INITIALIZERS, "struct", sym->name, sym->lineDef);
+ }
return;
}
if (!--lcnt) {
/* if initializers left */
if (iloop) {
- werror (W_EXESS_ARRAY_INITIALIZERS, sym->name, sym->lineDef);
+ werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
}
break;
}
/* check the type */
if (compareType (type, val->type) == 0)
- werror (E_INIT_WRONG);
+ werror (W_INIT_WRONG);
/* if val is literal */
if (IS_LITERAL (val->etype))
/* if type is SPECIFIER */
if (IS_SPEC (type))
{
- printIvalType (type, ilist, oFile);
+ printIvalType (sym, type, ilist, oFile);
return;
}
}
}
/* if the main is only a prototype ie. no body then do nothing */
- if (!mainf->fbody)
+ if (!IFFUNC_HASBODY(mainf->type))
{
/* if ! compile only then main function should be present */
if (!options.cc_only && !noAssemble)
copyFile (asmFile, ovrFile);
/* create the stack segment MOF */
- if (mainf && mainf->fbody)
+ if (mainf && IFFUNC_HASBODY(mainf->type))
{
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; Stack segment in internal ram \n");
copyFile (asmFile, bit->oFile);
/* if external stack then reserve space of it */
- if (mainf && mainf->fbody && options.useXstack)
+ if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack)
{
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; external stack \n");
copyFile (asmFile, xdata->oFile);
/* copy the interrupt vector table */
- if (mainf && mainf->fbody)
+ if (mainf && IFFUNC_HASBODY(mainf->type))
{
fprintf (asmFile, "%s", iComments2);
fprintf (asmFile, "; interrupt vector \n");
tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
tfprintf (asmFile, "\t!area\n", port->mem.static_name);
- if (mainf && mainf->fbody)
+ if (mainf && IFFUNC_HASBODY(mainf->type))
{
fprintf (asmFile, "__sdcc_gsinit_startup:\n");
/* if external stack is specified then the
}
copyFile (asmFile, statsg->oFile);
- if (port->general.glue_up_main && mainf && mainf->fbody)
+ if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type))
{
/* This code is generated in the post-static area.
* This area is guaranteed to follow the static area
fprintf (asmFile, "; code\n");
fprintf (asmFile, "%s", iComments2);
tfprintf (asmFile, "\t!areacode\n", CODE_NAME);
- if (mainf && mainf->fbody)
+ if (mainf && IFFUNC_HASBODY(mainf->type))
{
/* entry point @ start of CSEG */
}
#endif
+/** Creates a temporary file name a'la tmpnam which avoids the bugs
+ in cygwin wrt c:\tmp.
+ Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
+*/
+char *
+tempfilename (void)
+{
+#if !defined(_MSC_VER)
+ const char *tmpdir = NULL;
+ if (getenv ("TMP"))
+ tmpdir = getenv ("TMP");
+ else if (getenv ("TEMP"))
+ tmpdir = getenv ("TEMP");
+ else if (getenv ("TMPDIR"))
+ tmpdir = getenv ("TMPDIR");
+ if (tmpdir)
+ {
+ char *name = tempnam (tmpdir, "sdcc");
+ if (name)
+ {
+ return name;
+ }
+ }
+#endif
+ return tmpnam (NULL);
+}
+
/** Creates a temporary file a'la tmpfile which avoids the bugs
in cygwin wrt c:\tmp.
Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
tmpdir = getenv ("TMPDIR");
if (tmpdir)
{
- char *name = tempnam (tmpdir, "sdcc");
+ char *name = Safe_strdup( tempnam (tmpdir, "sdcc"));
if (name)
{
FILE *fp = fopen (name, "w+b");
return tmpfile ();
}
-char *
-gc_strdup (const char *s)
-{
- char *ret;
- ret = Safe_calloc (1, strlen (s) + 1);
- strcpy (ret, s);
- return ret;
-}